diff options
author | jhb <jhb@FreeBSD.org> | 2015-08-19 20:09:14 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2015-08-19 20:09:14 +0000 |
commit | f29b333753c5d595f78e6498d13dcc617e58bf0b (patch) | |
tree | 75ae61a374984880cf872eaf00496e172373b84a | |
parent | d59eb787d33a49d9306b829d039bc4cd84d86476 (diff) | |
download | FreeBSD-src-f29b333753c5d595f78e6498d13dcc617e58bf0b.zip FreeBSD-src-f29b333753c5d595f78e6498d13dcc617e58bf0b.tar.gz |
Always use %j with an intmax_t cast to print time_t values. time_t is
longer than long on 32-bit platforms with a 64-bit time_t.
Inspired by: mail from bde
-rw-r--r-- | usr.bin/truss/main.c | 18 | ||||
-rw-r--r-- | usr.bin/truss/syscalls.c | 35 |
2 files changed, 28 insertions, 25 deletions
diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index 1aac29f..84ae313 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -323,15 +324,15 @@ START_TRACE: if (trussinfo->flags & ABSOLUTETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->start_time, &timediff); - fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, + fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->curthread->before, &timediff); - fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, + fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } signame = strsig(trussinfo->pr_data); @@ -348,15 +349,16 @@ START_TRACE: if (trussinfo->flags & ABSOLUTETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->start_time, &timediff); - fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, + fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->curthread->before, &timediff); - fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, timediff.tv_nsec); + fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, + timediff.tv_nsec); } fprintf(trussinfo->outfile, "process exit, rval = %u\n", trussinfo->pr_data); diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index b8e8b52..c5bac55 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -993,7 +993,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, if (get_struct(pid, (void *)args[sc->offset], &ts, sizeof(ts)) != -1) - fprintf(fp, "{ %ld.%09ld }", (long)ts.tv_sec, + fprintf(fp, "{ %jd.%09ld }", (intmax_t)ts.tv_sec, ts.tv_nsec); else fprintf(fp, "0x%lx", args[sc->offset]); @@ -1019,8 +1019,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, fprintf(fp, "UTIME_OMIT"); break; default: - fprintf(fp, "%ld.%09ld", - (long)ts[i].tv_sec, ts[i].tv_nsec); + fprintf(fp, "%jd.%09ld", + (intmax_t)ts[i].tv_sec, + ts[i].tv_nsec); break; } } @@ -1034,7 +1035,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) != -1) - fprintf(fp, "{ %ld.%06ld }", (long)tv.tv_sec, + fprintf(fp, "{ %jd.%06ld }", (intmax_t)tv.tv_sec, tv.tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); @@ -1045,9 +1046,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv)) != -1) - fprintf(fp, "{ %ld.%06ld, %ld.%06ld }", - (long)tv[0].tv_sec, tv[0].tv_usec, - (long)tv[1].tv_sec, tv[1].tv_usec); + fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", + (intmax_t)tv[0].tv_sec, tv[0].tv_usec, + (intmax_t)tv[1].tv_sec, tv[1].tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); break; @@ -1057,10 +1058,10 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, if (get_struct(pid, (void *)args[sc->offset], &itv, sizeof(itv)) != -1) - fprintf(fp, "{ %ld.%06ld, %ld.%06ld }", - (long)itv.it_interval.tv_sec, + fprintf(fp, "{ %jd.%06ld, %jd.%06ld }", + (intmax_t)itv.it_interval.tv_sec, itv.it_interval.tv_usec, - (long)itv.it_value.tv_sec, + (intmax_t)itv.it_value.tv_sec, itv.it_value.tv_usec); else fprintf(fp, "0x%lx", args[sc->offset]); @@ -1410,9 +1411,9 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru)) != -1) { fprintf(fp, - "{ u=%ld.%06ld,s=%ld.%06ld,in=%ld,out=%ld }", - (long)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec, - (long)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec, + "{ u=%jd.%06ld,s=%jd.%06ld,in=%ld,out=%ld }", + (intmax_t)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec, + (intmax_t)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec, ru.ru_inblock, ru.ru_oublock); } else fprintf(fp, "0x%lx", args[sc->offset]); @@ -1513,15 +1514,15 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs, if (trussinfo->flags & ABSOLUTETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->start_time, &timediff); - len += fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, timediff.tv_nsec); + len += fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { timespecsubt(&trussinfo->curthread->after, &trussinfo->curthread->before, &timediff); - len += fprintf(trussinfo->outfile, "%ld.%09ld ", - (long)timediff.tv_sec, timediff.tv_nsec); + len += fprintf(trussinfo->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } len += fprintf(trussinfo->outfile, "%s(", name); |