aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils')
-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 @@
#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);
}