From: Alejandro Colomar <colomar.6.4.3@gmail.com>
To: mtk.manpages@gmail.com
Cc: Alejandro Colomar <colomar.6.4.3@gmail.com>,
linux-man@vger.kernel.org, linux-kernel@vger.kernel.org,
libc-alpha@sourceware.org
Subject: [PATCH v2] getdents.2: Use appropriate types
Date: Thu, 29 Oct 2020 14:42:11 +0100 [thread overview]
Message-ID: <20201029134210.191970-1-colomar.6.4.3@gmail.com> (raw)
In-Reply-To: <1195fda6-4de3-09fc-8653-42655d7e2b76@gmail.com>
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.
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.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
next prev parent reply other threads:[~2020-10-29 13:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20201028221118.158108-1-colomar.6.4.3@gmail.com>
[not found] ` <ed5937c4-a590-1735-b716-0894657ff8fc@gmail.com>
2020-10-29 11:02 ` [PATCH] getdents.2: Use 'ssize_t' instead of 'int' Alejandro Colomar
2020-10-29 13:42 ` Alejandro Colomar [this message]
2020-10-29 13:55 ` [PATCH v2] getdents.2: Use appropriate types 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=20201029134210.191970-1-colomar.6.4.3@gmail.com \
--to=colomar.6.4.3@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).