public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Alejandro Colomar <colomar.6.4.3@gmail.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org
Subject: Re: [PATCH] getdents.2: Use 'ssize_t' instead of 'int'
Date: Thu, 29 Oct 2020 08:13:48 +0100	[thread overview]
Message-ID: <ed5937c4-a590-1735-b716-0894657ff8fc@gmail.com> (raw)
In-Reply-To: <20201028221118.158108-1-colomar.6.4.3@gmail.com>

Hi Alex,

On 10/28/20 11:11 PM, Alejandro Colomar wrote:
> The glibc wrapper for getdents64() uses ssize_t.

It also changed the types for the arguments, so those need to be 
fixed too.

> And let's use it also for getdents().

I actually think we should *not* change that. So long as their is
no wrapper, we should show pretty much what the ABI exposes. (That
makes me think that the return type should really be long; see 
what you think about DEFINE_SYSCALL3 in the kernel sources.)

And you added an include for <sys/types.h>. I'm not sure 
whether that's needed, but it should be explained in the 
commit message.

Thanks,

Michael

> It makes more sense than int:
> It's a count of bytes, and can report an error (-1).
> 
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man2/getdents.2 | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/man2/getdents.2 b/man2/getdents.2
> index a187fbcef..d660f1bc1 100644
> --- a/man2/getdents.2
> +++ b/man2/getdents.2
> @@ -33,13 +33,13 @@
>  getdents, getdents64 \- get directory entries
>  .SH SYNOPSIS
>  .nf
> -.BI "int getdents(unsigned int " fd ", struct linux_dirent *" dirp ,
> +.BI "ssize_t 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 "ssize_t getdents64(unsigned int " fd ", struct linux_dirent64 *" dirp ,
>  .BI "             unsigned int " count );
>  .fi
>  .PP
> @@ -266,6 +266,7 @@ inode#    file type  d_reclen  d_off   d_name
>  #include <stdlib.h>
>  #include <sys/stat.h>
>  #include <sys/syscall.h>
> +#include <sys/types.h>
>  
>  #define handle_error(msg) \e
>          do { perror(msg); exit(EXIT_FAILURE); } while (0)
> @@ -282,7 +283,8 @@ struct linux_dirent {
>  int
>  main(int argc, char *argv[])
>  {
> -    int fd, nread;
> +    int fd;
> +    ssize_t nread;
>      char buf[BUF_SIZE];
>      struct linux_dirent *d;
>      char d_type;
> @@ -301,7 +303,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 (ssize_t bpos = 0; bpos < nread;) {
>              d = (struct linux_dirent *) (buf + bpos);
>              printf("%8ld  ", d\->d_ino);
>              d_type = *(buf + bpos + d\->d_reclen \- 1);
> 


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

  reply	other threads:[~2020-10-29  7:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 22:11 [PATCH] getdents.2: Use 'ssize_t' instead of 'int' Alejandro Colomar
2020-10-29  7:13 ` Michael Kerrisk (man-pages) [this message]
2020-10-29 11:02   ` Alejandro Colomar
2020-10-29 13:42     ` [PATCH v2] getdents.2: Use appropriate types Alejandro Colomar
2020-10-29 13:55       ` Michael Kerrisk (man-pages)
2020-10-29 14:10         ` [PATCH v3] " Alejandro Colomar
2020-10-29 19:54           ` Michael Kerrisk (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed5937c4-a590-1735-b716-0894657ff8fc@gmail.com \
    --to=mtk.manpages@gmail.com \
    --cc=colomar.6.4.3@gmail.com \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox