aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-03-26 11:44:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-03-26 11:44:48 +0100
commit973698d7b119114c4d5621f0f811efc04f4bc6d9 (patch)
tree878e1cfa64da32d7a4b29bf90ba68e664511fb46
parent3395e2a8efc92c2198620cce6f90d39bffcbb393 (diff)
downloadbusybox-w32-973698d7b119114c4d5621f0f811efc04f4bc6d9.tar.gz
busybox-w32-973698d7b119114c4d5621f0f811efc04f4bc6d9.tar.bz2
busybox-w32-973698d7b119114c4d5621f0f811efc04f4bc6d9.zip
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>
-rw-r--r--miscutils/ts.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/miscutils/ts.c b/miscutils/ts.c
index a2823721c..4e1c7739f 100644
--- a/miscutils/ts.c
+++ b/miscutils/ts.c
@@ -17,12 +17,11 @@
17 17
18#include "libbb.h" 18#include "libbb.h"
19#include "common_bufsiz.h" 19#include "common_bufsiz.h"
20# include <sys/syscall.h>
21 20
22int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 21int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
23int ts_main(int argc UNUSED_PARAM, char **argv) 22int ts_main(int argc UNUSED_PARAM, char **argv)
24{ 23{
25 struct timespec base; 24 struct timeval base;
26 unsigned opt; 25 unsigned opt;
27 char *frac; 26 char *frac;
28 char *fmt_dt2str; 27 char *fmt_dt2str;
@@ -48,28 +47,25 @@ int ts_main(int argc UNUSED_PARAM, char **argv)
48 47
49#define date_buf bb_common_bufsiz1 48#define date_buf bb_common_bufsiz1
50 setup_common_bufsiz(); 49 setup_common_bufsiz();
51 syscall(__NR_clock_gettime, CLOCK_REALTIME, &base); 50 gettimeofday(&base, NULL);
52 51
53 while ((line = xmalloc_fgets(stdin)) != NULL) { 52 while ((line = xmalloc_fgets(stdin)) != NULL) {
54 struct timespec ts; 53 struct timeval ts;
55 struct tm tm_time; 54 struct tm tm_time;
56 55
57 /* libc has incredibly messy way of doing this, 56 gettimeofday(&ts, NULL);
58 * typically requiring -lrt. We just skip all this mess
59 */
60 syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
61 if (opt) { 57 if (opt) {
62 /* -i and/or -s */ 58 /* -i and/or -s */
63 struct timespec ts1 = ts1; 59 struct timeval ts1 = ts1;
64 if (opt & 1) /* -i */ 60 if (opt & 1) /* -i */
65 ts1 = ts; 61 ts1 = ts;
66//printf("%d %d\n", ts.tv_sec, base.tv_sec); 62//printf("%d %d\n", ts.tv_sec, base.tv_sec);
67 ts.tv_sec -= base.tv_sec; 63 ts.tv_sec -= base.tv_sec;
68//printf("%d %d\n", ts.tv_sec, base.tv_sec); 64//printf("%d %d\n", ts.tv_sec, base.tv_sec);
69 ts.tv_nsec -= base.tv_nsec; 65 ts.tv_usec -= base.tv_usec;
70 if ((int32_t)(ts.tv_nsec) < 0) { 66 if ((int32_t)(ts.tv_usec) < 0) {
71 ts.tv_sec--; 67 ts.tv_sec--;
72 ts.tv_nsec += 1000*1000*1000; 68 ts.tv_usec += 1000*1000;
73 } 69 }
74 if (opt & 1) /* -i */ 70 if (opt & 1) /* -i */
75 base = ts1; 71 base = ts1;
@@ -79,7 +75,7 @@ int ts_main(int argc UNUSED_PARAM, char **argv)
79 if (!frac) { 75 if (!frac) {
80 printf("%s %s", date_buf, line); 76 printf("%s %s", date_buf, line);
81 } else { 77 } else {
82 printf("%s.%06u %s", date_buf, (unsigned)ts.tv_nsec / 1000u, line); 78 printf("%s.%06u %s", date_buf, (unsigned)ts.tv_usec, line);
83 } 79 }
84 free(line); 80 free(line);
85 } 81 }