[Jamie Lokier <jamie.lokier@cern.ch>] libc/1068: [glibc] Possible erroneous return code from Linux __getdirentries
Andreas Jaeger
aj@arthur.rhein-neckar.de
Wed Apr 7 04:34:00 GMT 1999
We've received the appended bug report about a problem with
getdirentries.
The linux man page states:
RETURN VALUE
getdirentries returns the number of bytes read or zero
when at the end of the directory. If an error occurs, -1
is returned, and errno is set appropriately.
and <dirent.h> has:
/* Read directory entries from FD into BUF, reading at most NBYTES.
Reading starts at offset *BASEP, and *BASEP is updated with the new
position after reading. Returns the number of bytes read; zero when at
end of directory; or -1 for errors. */
We could (as my appended patch does) directly return the -1 from
getdents for errors. Is this the right semantic?
Andreas
1999-04-07 Andreas Jaeger <aj@arthur.rhein-neckar.de>
* sysdeps/unix/sysv/linux/getdents.c (__getdirentries): Return
directly if getdents returns with error set.
--- sysdeps/unix/sysv/linux/getdents.c.~1~ Thu Oct 22 07:37:46 1998
+++ sysdeps/unix/sysv/linux/getdents.c Wed Apr 7 13:29:55 1999
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -82,6 +82,9 @@
retval = INLINE_SYSCALL (getdents, 3, fd, (char *) kdp, red_nbytes);
+ if (retval == -1)
+ return -1;
+
while ((char *) kdp < (char *) skdp + retval)
{
const size_t alignment = __alignof__ (struct dirent);
More information about the Libc-alpha
mailing list