wkz / mdio-tools

Low-level debug tools for MDIO devices.
GNU General Public License v2.0
66 stars 31 forks source link

mdio: bench: make time_t prints portable #14

Closed robimarko closed 2 years ago

robimarko commented 2 years ago

Using %ld to print time_t will work fine on 64 bit platforms, however now musl libc defines time_t to be 64 even on 32bit platforms.

This will make the compilation fail with:

mdio.c: In function 'mdio_common_bench_cb':
mdio.c:555:27: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'time_t' {aka 'long long int'} [-Werror=format=]
  555 |                 printf("%ld.%2.2lds\n", end.tv_sec, end.tv_nsec / 10000000);
      |                         ~~^             ~~~~~~~~~~
      |                           |                |
      |                           long int         time_t {aka long long int}
      |                         %lld

So, replace the %ld in prints with the PRId64 from inttypes.h and cast tv_sec and tv_nsec to int64_t.

This makes it compile and work on 32 bit ARMv7 fine.

Signed-off-by: Robert Marko robert.marko@sartura.hr

wkz commented 2 years ago

I should add a musl toolchain to the build tests :smile: Thanks!