[PATCH v2 10/24] ioctl_ns.2: Cast to 'unsigned long' rather than 'long' when printing with "%lx"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

On 2020-09-11 09:24, Michael Kerrisk (man-pages) wrote:
This may be true on Linux, but is not true on other systems.
For example, on HP-UX, according to one header file I'm
looking at, the return value is 'long'. >
These kinds of casts are intended to improve code portability
across UNIX implementations, so I think they should stay
(although, I do wonder if they would be even better as casts
to 'unsigned long')

Fine, then here is the patch with the casts to 'unsigned long'.

Cheers,

Alex

-------------------------------------------------------------
From c5f644e798ffc5dec0c73f324a26059568865c68 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx>
Date: Fri, 11 Sep 2020 10:51:26 +0200
Subject: [PATCH v2 10/24] ioctl_ns.2: Cast to 'unsigned long' rather than 'long'
 when printing with "%lx"

From the email conversation:

On 2020-09-11 09:24, Michael Kerrisk (man-pages) wrote:
> Hi Alex,
>
> On 9/10/20 11:13 PM, Alejandro Colomar wrote:
>> Both major(3) and minor(3) return an 'unsigned int',
>> so there is no need to use a 'long' for printing.
>> Moreover, it should have been 'unsigned long',
>> as "%lx" expects an unsigned type.
>
> This may be true on Linux, but is not true on other systems.
> For example, on HP-UX, according to one header file I'm
> looking at, the return value is 'long'.
>
> These kinds of casts are intended to improve code portability
> across UNIX implementations, so I think they should stay
> (although, I do wonder if they would be even better as casts
> to 'unsigned long')
>
> Thanks,
>
> Michael

Signed-off-by: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx>
---
 man2/ioctl_ns.2 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/man2/ioctl_ns.2 b/man2/ioctl_ns.2
index 818dde32c..8b8789d1f 100644
--- a/man2/ioctl_ns.2
+++ b/man2/ioctl_ns.2
@@ -317,7 +317,8 @@ main(int argc, char *argv[])
         }
         printf("Device/Inode of owning user namespace is: "
                 "[%lx,%lx] / %ld\en",
-                (long) major(sb.st_dev), (long) minor(sb.st_dev),
+                (unsigned long) major(sb.st_dev),
+                (unsigned long) minor(sb.st_dev),
                 (long) sb.st_ino);

         close(userns_fd);
@@ -346,7 +347,8 @@ main(int argc, char *argv[])
             exit(EXIT_FAILURE);
         }
         printf("Device/Inode of parent namespace is: [%lx,%lx] / %ld\en",
-                (long) major(sb.st_dev), (long) minor(sb.st_dev),
+                (unsigned long) major(sb.st_dev),
+                (unsigned long) minor(sb.st_dev),
                 (long) sb.st_ino);

         close(parent_fd);
--
2.28.0



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux