diff mbox series

[libgpiod-v2] gpiomon: Fix format specifier for uint64_t

Message ID 20210728131327.GA14442@cephalopod
State New
Headers show
Series [libgpiod-v2] gpiomon: Fix format specifier for uint64_t | expand

Commit Message

Ben Hutchings July 28, 2021, 1:13 p.m. UTC
uint64_t might be defined as either unsigned long or unsigned long
long, depending on the architecture.  Values of this type should be
formatted with the specifier PRIu64 rather than "ld".

Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
---
 tools/gpiomon.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Bartosz Golaszewski July 29, 2021, 2:34 p.m. UTC | #1
On Wed, Jul 28, 2021 at 3:13 PM Ben Hutchings <ben.hutchings@mind.be> wrote:
>
> uint64_t might be defined as either unsigned long or unsigned long
> long, depending on the architecture.  Values of this type should be
> formatted with the specifier PRIu64 rather than "ld".
>
> Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
> ---
>  tools/gpiomon.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/tools/gpiomon.c b/tools/gpiomon.c
> index 2b5966c..df86a46 100644
> --- a/tools/gpiomon.c
> +++ b/tools/gpiomon.c
> @@ -4,6 +4,7 @@
>  #include <errno.h>
>  #include <getopt.h>
>  #include <gpiod.h>
> +#include <inttypes.h>
>  #include <limits.h>
>  #include <poll.h>
>  #include <signal.h>
> @@ -95,10 +96,10 @@ static void event_print_custom(unsigned int offset, uint64_t timeout,
>                                 fputc('0', stdout);
>                         break;
>                 case 's':
> -                       printf("%ld", timeout / 1000000000);
> +                       printf("%"PRIu64, timeout / 1000000000);
>                         break;
>                 case 'n':
> -                       printf("%ld", timeout % 1000000000);
> +                       printf("%"PRIu64, timeout % 1000000000);
>                         break;
>                 case '%':
>                         fputc('%', stdout);
> @@ -129,7 +130,7 @@ static void event_print_human_readable(unsigned int offset,
>         else
>                 evname = "FALLING EDGE";
>
> -       printf("event: %s offset: %u timestamp: [%8ld.%09ld]\n",
> +       printf("event: %s offset: %u timestamp: [%8"PRIu64".%09"PRIu64"]\n",
>                evname, offset, timeout / 1000000000, timeout % 1000000000);
>  }
>
> --
> 2.20.1

Hi Ben!

This and the other patches are great, thanks!

I assume they are rebases on top of the next/libpiod-2.0 branch? I
want the git repo for libgpiod to remain bisectable and intend to
switch to the new API in one big patch including the core API, C++ and
Python bindings as well as test suites. I will keep your patches in my
queue and apply them once the patch is in master - unless you don't
care that much about authorship of the patches in which case I can
squash them into the big patch and credit you in the commit message.
Let me know what works best for you.

Bart
Ben Hutchings July 30, 2021, 2:12 p.m. UTC | #2
On Thu, Jul 29, 2021 at 04:34:19PM +0200, Bartosz Golaszewski wrote:
[...] 
> Hi Ben!

> 

> This and the other patches are great, thanks!

> 

> I assume they are rebases on top of the next/libpiod-2.0 branch?


That's right.

> I

> want the git repo for libgpiod to remain bisectable and intend to

> switch to the new API in one big patch including the core API, C++ and

> Python bindings as well as test suites. I will keep your patches in my

> queue and apply them once the patch is in master - unless you don't

> care that much about authorship of the patches in which case I can

> squash them into the big patch and credit you in the commit message.

> Let me know what works best for you.


Please squash this one into the big patch (as it fixes a regression in
that) and apply the others separately.

Ben.

-- 
Ben Hutchings · Senior Embedded Software Engineer, Essensium-Mind · mind.be
diff mbox series

Patch

diff --git a/tools/gpiomon.c b/tools/gpiomon.c
index 2b5966c..df86a46 100644
--- a/tools/gpiomon.c
+++ b/tools/gpiomon.c
@@ -4,6 +4,7 @@ 
 #include <errno.h>
 #include <getopt.h>
 #include <gpiod.h>
+#include <inttypes.h>
 #include <limits.h>
 #include <poll.h>
 #include <signal.h>
@@ -95,10 +96,10 @@  static void event_print_custom(unsigned int offset, uint64_t timeout,
 				fputc('0', stdout);
 			break;
 		case 's':
-			printf("%ld", timeout / 1000000000);
+			printf("%"PRIu64, timeout / 1000000000);
 			break;
 		case 'n':
-			printf("%ld", timeout % 1000000000);
+			printf("%"PRIu64, timeout % 1000000000);
 			break;
 		case '%':
 			fputc('%', stdout);
@@ -129,7 +130,7 @@  static void event_print_human_readable(unsigned int offset,
 	else
 		evname = "FALLING EDGE";
 
-	printf("event: %s offset: %u timestamp: [%8ld.%09ld]\n",
+	printf("event: %s offset: %u timestamp: [%8"PRIu64".%09"PRIu64"]\n",
 	       evname, offset, timeout / 1000000000, timeout % 1000000000);
 }