Skip to content

Commit

Permalink
Always use "%lld" for formatting time_ts
Browse files Browse the repository at this point in the history
Given the following test program:
  #include <time.h>
  #include <stdio.h>
  #include <stdint.h>
  int main() {
    printf("time_t:    %d\n", sizeof(time_t));
    printf("long:      %d\n", sizeof(long));
    printf("long long: %d\n", sizeof(long long));
  }

These are output on various x86 architectures:
  x32$   time_t:    8
  x32$   long:      4
  x32$   long long: 8

  amd64$ time_t:    8
  amd64$ long:      8
  amd64$ long long: 8

  i386$  time_t:    4
  i386$  long:      4
  i386$  long long: 8

Therefore code using "%l[du]" to format time_ts produced warnings on x32

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#10357
Closes openzfs#844
(cherry picked from commit a1ba120)
  • Loading branch information
nabijaczleweli authored and as-com committed Jun 20, 2020
1 parent dca2429 commit c39d4a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/libspl/timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ print_timestamp(uint_t timestamp_fmt)
fmt = nl_langinfo(_DATE_FMT);

if (timestamp_fmt == UDATE) {
(void) printf("%ld\n", t);
(void) printf("%lld\n", (longlong_t)t);
} else if (timestamp_fmt == DDATE) {
char dstr[64];
int len;
Expand Down
4 changes: 2 additions & 2 deletions lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4888,8 +4888,8 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
zfs_nicebytes(bytes, buf1, sizeof (buf1));
zfs_nicebytes(bytes/delta, buf2, sizeof (buf1));

(void) printf("received %s stream in %lu seconds (%s/sec)\n",
buf1, delta, buf2);
(void) printf("received %s stream in %lld seconds (%s/sec)\n",
buf1, (longlong_t)delta, buf2);
}

err = 0;
Expand Down

0 comments on commit c39d4a5

Please sign in to comment.