lkml.org 
[lkml]   [2020]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 10/24] ioctl_ns.2: Remove unneeded cast
From
Date
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@gmail.com>
> ---
> man2/ioctl_ns.2 | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/man2/ioctl_ns.2 b/man2/ioctl_ns.2
> index 818dde32c..bf832a2c7 100644
> --- a/man2/ioctl_ns.2
> +++ b/man2/ioctl_ns.2
> @@ -316,9 +316,8 @@ main(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
> printf("Device/Inode of owning user namespace is: "
> - "[%lx,%lx] / %ld\en",
> - (long) major(sb.st_dev), (long) minor(sb.st_dev),
> - (long) sb.st_ino);
> + "[%x,%x] / %ld\en",
> + major(sb.st_dev), minor(sb.st_dev), (long) sb.st_ino);
>
> close(userns_fd);
> }
> @@ -345,9 +344,8 @@ main(int argc, char *argv[])
> perror("fstat\-parentns");
> exit(EXIT_FAILURE);
> }
> - printf("Device/Inode of parent namespace is: [%lx,%lx] / %ld\en",
> - (long) major(sb.st_dev), (long) minor(sb.st_dev),
> - (long) sb.st_ino);
> + printf("Device/Inode of parent namespace is: [%x,%x] / %ld\en",
> + major(sb.st_dev), minor(sb.st_dev), (long) sb.st_ino);
>
> close(parent_fd);
> }
>


--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

\
 
 \ /
  Last update: 2020-09-11 09:25    [W:0.756 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site