[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKgNAkgi7MAW9PxKNBFQ07r7p2PFRR3xU2BJBTqk8oiXDJ4NXA@mail.gmail.com>
Date: Thu, 29 Oct 2020 14:55:21 +0100
From: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>
To: Alejandro Colomar <colomar.6.4.3@...il.com>
Cc: linux-man <linux-man@...r.kernel.org>,
lkml <linux-kernel@...r.kernel.org>,
"libc-alpha@...rceware.org" <libc-alpha@...rceware.org>
Subject: Re: [PATCH v2] getdents.2: Use appropriate types
Hi Alex,
On Thu, 29 Oct 2020 at 14:42, Alejandro Colomar <colomar.6.4.3@...il.com> wrote:
>
> getdents():
> This function has no glibc wrapper.
> As such, we should use the same types the Linux kernel uses:
> Use 'long' as the return type.
>
> getdents64():
> The glibc wrapper uses ssize_t for the return type,
> and 'size_t' for the count argument.
Take a look in the header file at the argument types for getdents64();
there's still some changes needed.
Thanks,
Michael
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@...il.com>
> ---
> man2/getdents.2 | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/man2/getdents.2 b/man2/getdents.2
> index a187fbcef..e14627e6e 100644
> --- a/man2/getdents.2
> +++ b/man2/getdents.2
> @@ -33,14 +33,14 @@
> getdents, getdents64 \- get directory entries
> .SH SYNOPSIS
> .nf
> -.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> +.BI "long getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> .BI " unsigned int " count );
> .PP
> .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
> .B #include <dirent.h>
> .PP
> -.BI "int getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
> -.BI " unsigned int " count );
> +.BI "ssize_t getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
> +.BI " size_t " count );
> .fi
> .PP
> .IR Note :
> @@ -282,7 +282,8 @@ struct linux_dirent {
> int
> main(int argc, char *argv[])
> {
> - int fd, nread;
> + int fd;
> + long nread;
> char buf[BUF_SIZE];
> struct linux_dirent *d;
> char d_type;
> @@ -301,7 +302,7 @@ main(int argc, char *argv[])
>
> printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
> printf("inode# file type d_reclen d_off d_name\en");
> - for (int bpos = 0; bpos < nread;) {
> + for (long bpos = 0; bpos < nread;) {
> d = (struct linux_dirent *) (buf + bpos);
> printf("%8ld ", d\->d_ino);
> d_type = *(buf + bpos + d\->d_reclen \- 1);
> --
> 2.28.0
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Powered by blists - more mailing lists