diff options
author | Denys Vlasenko | 2019-03-26 11:44:48 +0100 |
---|---|---|
committer | Denys Vlasenko | 2019-03-26 11:44:48 +0100 |
commit | 973698d7b119114c4d5621f0f811efc04f4bc6d9 (patch) | |
tree | 878e1cfa64da32d7a4b29bf90ba68e664511fb46 /miscutils/ts.c | |
parent | 3395e2a8efc92c2198620cce6f90d39bffcbb393 (diff) | |
download | busybox-973698d7b119114c4d5621f0f811efc04f4bc6d9.zip busybox-973698d7b119114c4d5621f0f811efc04f4bc6d9.tar.gz |
ts: use gettimeofday - we don't use nanoseconds here
function old new delta
ts_main 398 376 -22
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/ts.c')
-rw-r--r-- | miscutils/ts.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/miscutils/ts.c b/miscutils/ts.c index a282372..4e1c773 100644 --- a/miscutils/ts.c +++ b/miscutils/ts.c @@ -17,12 +17,11 @@ #include "libbb.h" #include "common_bufsiz.h" -# include <sys/syscall.h> int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ts_main(int argc UNUSED_PARAM, char **argv) { - struct timespec base; + struct timeval base; unsigned opt; char *frac; char *fmt_dt2str; @@ -48,28 +47,25 @@ int ts_main(int argc UNUSED_PARAM, char **argv) #define date_buf bb_common_bufsiz1 setup_common_bufsiz(); - syscall(__NR_clock_gettime, CLOCK_REALTIME, &base); + gettimeofday(&base, NULL); while ((line = xmalloc_fgets(stdin)) != NULL) { - struct timespec ts; + struct timeval ts; struct tm tm_time; - /* libc has incredibly messy way of doing this, - * typically requiring -lrt. We just skip all this mess - */ - syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts); + gettimeofday(&ts, NULL); if (opt) { /* -i and/or -s */ - struct timespec ts1 = ts1; + struct timeval ts1 = ts1; if (opt & 1) /* -i */ ts1 = ts; //printf("%d %d\n", ts.tv_sec, base.tv_sec); ts.tv_sec -= base.tv_sec; //printf("%d %d\n", ts.tv_sec, base.tv_sec); - ts.tv_nsec -= base.tv_nsec; - if ((int32_t)(ts.tv_nsec) < 0) { + ts.tv_usec -= base.tv_usec; + if ((int32_t)(ts.tv_usec) < 0) { ts.tv_sec--; - ts.tv_nsec += 1000*1000*1000; + ts.tv_usec += 1000*1000; } if (opt & 1) /* -i */ base = ts1; @@ -79,7 +75,7 @@ int ts_main(int argc UNUSED_PARAM, char **argv) if (!frac) { printf("%s %s", date_buf, line); } else { - printf("%s.%06u %s", date_buf, (unsigned)ts.tv_nsec / 1000u, line); + printf("%s.%06u %s", date_buf, (unsigned)ts.tv_usec, line); } free(line); } |