Cleanup UTIME_NOW/UTIME_OMIT decoding
Move the code that's present in two copies from sprinttv()
to a new helper function.
* time.c (do_sprinttv): New function.
(sprinttv): Use it.
diff --git a/time.c b/time.c
index 68efc80..31f0846 100644
--- a/time.c
+++ b/time.c
@@ -66,11 +66,24 @@
tprints(buf);
}
+static char *
+do_sprinttv(char *buf, const unsigned long sec, const unsigned long usec,
+ const int special)
+{
+ if (special) {
+ switch (usec) {
+ case UTIME_NOW:
+ return stpcpy(buf, "UTIME_NOW");
+ case UTIME_OMIT:
+ return stpcpy(buf, "UTIME_OMIT");
+ }
+ }
+ return buf + sprintf(buf, "{%lu, %lu}", sec, usec);
+}
+
char *
sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
{
- int rc;
-
if (addr == 0)
return stpcpy(buf, "NULL");
@@ -85,32 +98,13 @@
{
struct timeval32 tv;
- rc = umove(tcp, addr, &tv);
- if (rc >= 0) {
- if (special) {
- if (tv.tv_usec == UTIME_NOW)
- return stpcpy(buf, "UTIME_NOW");
- if (tv.tv_usec == UTIME_OMIT)
- return stpcpy(buf, "UTIME_OMIT");
- }
- return buf + sprintf(buf, "{%u, %u}",
- tv.tv_sec, tv.tv_usec);
- }
+ if (umove(tcp, addr, &tv) >= 0)
+ return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
} else {
struct timeval tv;
- rc = umove(tcp, addr, &tv);
- if (rc >= 0) {
- if (special) {
- if (tv.tv_usec == UTIME_NOW)
- return stpcpy(buf, "UTIME_NOW");
- if (tv.tv_usec == UTIME_OMIT)
- return stpcpy(buf, "UTIME_OMIT");
- }
- return buf + sprintf(buf, "{%lu, %lu}",
- (unsigned long) tv.tv_sec,
- (unsigned long) tv.tv_usec);
- }
+ if (umove(tcp, addr, &tv) >= 0)
+ return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
}
return stpcpy(buf, "{...}");