>From 972a46f6061a5147c0c8f5e24c48bb83dd9f8d1b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 31 Aug 2017 14:34:24 -0700 Subject: [PATCH 2/3] glob, backupfile: inode 0 is a valid inode number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/posix-functions/readdir.texi (readdir): * doc/posix-headers/dirent.texi (dirent.h): Document more readdir portability issues. * lib/backupfile.c (REAL_DIR_ENTRY): Remove. (numbered_backup): Don’t treat inode 0 any differently from other inode values. * lib/glob.c (struct readdir_result): Remove skip_entry member. (readdir_result_skip_entry, D_INO_TO_RESULT): Remove. All uses removed. * modules/glob (Depends-on): Remove d-ino. --- ChangeLog | 12 ++++++++++++ doc/posix-functions/readdir.texi | 8 ++++++++ doc/posix-headers/dirent.texi | 25 +++++++++++++++++++++++++ lib/backupfile.c | 7 +------ lib/glob.c | 21 --------------------- modules/glob | 1 - 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index f372dbd38..53945d434 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2017-08-31 Paul Eggert + glob, backupfile: inode 0 is a valid inode number + * doc/posix-functions/readdir.texi (readdir): + * doc/posix-headers/dirent.texi (dirent.h): + Document more readdir portability issues. + * lib/backupfile.c (REAL_DIR_ENTRY): Remove. + (numbered_backup): Don’t treat inode 0 any differently from + other inode values. + * lib/glob.c (struct readdir_result): Remove skip_entry member. + (readdir_result_skip_entry, D_INO_TO_RESULT): Remove. + All uses removed. + * modules/glob (Depends-on): Remove d-ino. + glob: simplify symlink detection * lib/glob.c (dirent_type): New type. Use uint_fast8_t not uint8_t, as C99 does not require uint8_t. diff --git a/doc/posix-functions/readdir.texi b/doc/posix-functions/readdir.texi index a9da77a14..701a10faf 100644 --- a/doc/posix-functions/readdir.texi +++ b/doc/posix-functions/readdir.texi @@ -20,4 +20,12 @@ incorrectly. (Cf. @code{AC_SYS_LARGEFILE}.) Portability problems not fixed by Gnulib: @itemize address@hidden +Although POSIX places no restrictions on @code{d_ino} values, some +older systems are rumored to return @code{d_ino} values equal to zero +for directory entries that do not really exist. Although Gnulib +formerly attempted to cater to these older systems, this caused +misbehavior on standard systems and so Gnulib does not attempt to +cater to them any more. If you know of any problems caused by this, +please send a bug report. @end itemize diff --git a/doc/posix-headers/dirent.texi b/doc/posix-headers/dirent.texi index b61f82687..0a19fd3c2 100644 --- a/doc/posix-headers/dirent.texi +++ b/doc/posix-headers/dirent.texi @@ -17,4 +17,29 @@ Portability problems not fixed by Gnulib: @item This header file is missing on some platforms: MSVC 14. + address@hidden +Although many systems define a @code{struct dirent} member named address@hidden and directory entry type macros like @code{DT_DIR} and address@hidden, some do not: +AIX 7.2, HP-UX 11, Solaris 11, probably others. + address@hidden +On systems with @code{d_type}, not every filesystem supports address@hidden, and those lacking support will set it to @code{DT_UNKNOWN}. + address@hidden +Some systems define a @code{struct dirent} member named @code{d_namlen} +containing the string length of @code{d_name}, but others do not. + address@hidden +Some systems define a @code{struct dirent} member named @code{d_off} +containing a magic cookie suitable as an argument to @code{seekdir}, +but others do not. + address@hidden +Some systems define a @code{struct dirent} member named address@hidden containing the number of bytes in the directory entry +record, but others do not. This member has limited utility, as it is +an implementation detail. @end itemize diff --git a/lib/backupfile.c b/lib/backupfile.c index d7115bd61..ae171ecee 100644 --- a/lib/backupfile.c +++ b/lib/backupfile.c @@ -40,11 +40,6 @@ #ifndef _D_EXACT_NAMLEN # define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) #endif -#if D_INO_IN_DIRENT -# define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0) -#else -# define REAL_DIR_ENTRY(dp) 1 -#endif #if ! (HAVE_PATHCONF && defined _PC_NAME_MAX) # define pathconf(file, option) (errno = -1) @@ -225,7 +220,7 @@ numbered_backup (char **buffer, size_t buffer_size, size_t filelen, bool all_9s; size_t versionlen; - if (! REAL_DIR_ENTRY (dp) || _D_EXACT_NAMLEN (dp) < baselen + 4) + if (_D_EXACT_NAMLEN (dp) < baselen + 4) continue; if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0) diff --git a/lib/glob.c b/lib/glob.c index 6113af6fd..106f4cb26 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -113,9 +113,6 @@ struct readdir_result #if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE dirent_type type; #endif -#if defined _LIBC || defined D_INO_IN_DIRENT - bool skip_entry; -#endif }; /* Initialize and return type member of struct readdir_result. */ @@ -131,28 +128,12 @@ readdir_result_type (struct readdir_result d) #endif } -/* Initialize and return skip_entry member of struct readdir_result. */ -static bool -readdir_result_skip_entry (struct readdir_result d) -{ -/* Initializer for skip_entry. POSIX does not require that the d_ino - field be present, and some systems do not provide it. */ -#if defined _LIBC || defined D_INO_IN_DIRENT -# define D_INO_TO_RESULT(source) (source)->d_ino == 0, - return d.skip_entry; -#else -# define D_INO_TO_RESULT(source) - return false; -#endif -} - /* Construct an initializer for a struct readdir_result object from a struct dirent *. No copy of the name is made. */ #define READDIR_RESULT_INITIALIZER(source) \ { \ source->d_name, \ D_TYPE_TO_RESULT (source) \ - D_INO_TO_RESULT (source) \ } /* Call gl_readdir on STREAM. This macro can be overridden to reduce @@ -1543,8 +1524,6 @@ glob_in_dir (const char *pattern, const char *directory, int flags, } if (d.name == NULL) break; - if (readdir_result_skip_entry (d)) - continue; /* If we shall match only directories use the information provided by the dirent call if possible. */ diff --git a/modules/glob b/modules/glob index 48cf387bd..0d6209de6 100644 --- a/modules/glob +++ b/modules/glob @@ -20,7 +20,6 @@ snippet/warn-on-use alloca [test -n "$GLOB_H"] builtin-expect [test -n "$GLOB_H"] closedir [test -n "$GLOB_H"] -d-ino [test -n "$GLOB_H"] d-type [test -n "$GLOB_H"] dirfd [test -n "$GLOB_H"] flexmember [test -n "$GLOB_H"] -- 2.13.5