diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-01-20 11:04:04 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-01-20 11:04:04 +0100 |
commit | a1d541ec56e2fb4716f083fcc814b1dedde63d87 (patch) | |
tree | dd93ffd232792fac178a1de6bf646c099bdbdc49 /time.c | |
parent | b3c52cf02ae536634898cd12afa5f3fcad17fbf2 (diff) | |
download | strace-a1d541ec56e2fb4716f083fcc814b1dedde63d87.tar.gz strace-a1d541ec56e2fb4716f083fcc814b1dedde63d87.tar.bz2 strace-a1d541ec56e2fb4716f083fcc814b1dedde63d87.tar.xz |
Eliminate code duplication in time printing, reduce a few static buffers
text data bss dec hex filename
238454 664 28772 267890 41672 strace.before
238106 664 28676 267446 414b6 strace
* defs.h: Add TIMESPEC_TEXT_BUFSIZE and TIMEVAL_TEXT_BUFSIZE defines.
Add 'int special' parameter to sprinttv().
* time.c (sprinttv): Add 'int special' parameter, and use it
similarly to 'int special' parameter of printtv_bitness().
(printtv_bitness): Use sprinttv() instead of duplicating its code.
(print_timespec): Use sprint_timespec() instead of duplicating
its code.
* desc.c (decode_select): Use TIMEVAL_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.
* net.c (sys_recvmsg): Use TIMESPEC_TEXT_BUFSIZE instead of 128
for static buffer size.
* stream.c (decode_poll): Use TIMESPEC_TEXT_BUFSIZE instead of 128
when checking remaining buffer size.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 105 |
1 files changed, 27 insertions, 78 deletions
@@ -66,54 +66,13 @@ tprint_timeval(struct tcb *tcp, const struct timeval *tv) void printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special) { - if (addr == 0) - tprints("NULL"); - else if (!verbose(tcp)) - tprintf("%#lx", addr); - else { - int rc; - - if (bitness == BITNESS_32 -#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1 - || personality_wordsize[current_personality] == 4 -#endif - ) - { - struct timeval32 tv; - - rc = umove(tcp, addr, &tv); - if (rc >= 0) { - if (special && tv.tv_sec == 0 && - tv.tv_usec == UTIME_NOW) - tprints("UTIME_NOW"); - else if (special && tv.tv_sec == 0 && - tv.tv_usec == UTIME_OMIT) - tprints("UTIME_OMIT"); - else - tprint_timeval32(tcp, &tv); - } - } else { - struct timeval tv; - - rc = umove(tcp, addr, &tv); - if (rc >= 0) { - if (special && tv.tv_sec == 0 && - tv.tv_usec == UTIME_NOW) - tprints("UTIME_NOW"); - else if (special && tv.tv_sec == 0 && - tv.tv_usec == UTIME_OMIT) - tprints("UTIME_OMIT"); - else - tprint_timeval(tcp, &tv); - } - } - if (rc < 0) - tprints("{...}"); - } + char buf[TIMEVAL_TEXT_BUFSIZE]; + sprinttv(buf, tcp, addr, bitness, special); + tprints(buf); } char * -sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf) +sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special) { int rc; @@ -132,56 +91,46 @@ sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf) struct timeval32 tv; rc = umove(tcp, addr, &tv); - if (rc >= 0) + if (rc >= 0) { + if (special && tv.tv_sec == 0) { + 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); + } } else { struct timeval tv; rc = umove(tcp, addr, &tv); - if (rc >= 0) + if (rc >= 0) { + if (special && tv.tv_sec == 0) { + 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); + } } return stpcpy(buf, "{...}"); } -void print_timespec(struct tcb *tcp, long addr) +void +print_timespec(struct tcb *tcp, long addr) { - if (addr == 0) - tprints("NULL"); - else if (!verbose(tcp)) - tprintf("%#lx", addr); - else { - int rc; - -#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1 - if (personality_wordsize[current_personality] == 4) { - struct timeval32 tv; - - rc = umove(tcp, addr, &tv); - if (rc >= 0) - tprintf("{%u, %u}", - tv.tv_sec, tv.tv_usec); - } else -#endif - { - struct timespec ts; - - rc = umove(tcp, addr, &ts); - if (rc >= 0) - tprintf("{%lu, %lu}", - (unsigned long) ts.tv_sec, - (unsigned long) ts.tv_nsec); - } - if (rc < 0) - tprints("{...}"); - } + char buf[TIMESPEC_TEXT_BUFSIZE]; + sprint_timespec(buf, tcp, addr); + tprints(buf); } -void sprint_timespec(char *buf, struct tcb *tcp, long addr) +void +sprint_timespec(char *buf, struct tcb *tcp, long addr) { if (addr == 0) strcpy(buf, "NULL"); |