+2024-10-02 Paul Eggert <eggert@cs.ucla.edu>
+
+ dirent: define DT_* macros on all platforms
+ * lib/dirent.in.h (DT_UNKNOWN, DT_FIFO, DT_CHR, DT_DIR, DT_BLK)
+ (DT_REG, DT_LNK, DT_SOCK, DT_WHT): Define these on all platforms,
+ if the system does not already define them. Check that they
+ have distinct values.
+ (_GL_DIRENT_S_ISWHT, _GL_DIRENT_S_IFWHT) [!(IFTODT && DTTOIF)]:
+ New macros.
+ (IFTODT, DTTOIF): Define if not already defined.
+ * modules/dirent (Depends-on): Add assert-h, extensions.
+
2024-10-02 Bruno Haible <bruno@clisp.org>
Silence -Wunused-const-variable warnings in Gnulib code.
This header file is missing on some platforms:
MSVC 14.
+@item
+Although many systems define directory entry type macros like @code{DT_DIR},
+some do not:
+Minix 3.1.8, AIX 7.2, HP-UX 11, Solaris 11.4, mingw.
+
+@item
+The directory entry type macro @code{DT_WHT} is missing on many systems:
+All systems where @code{DT_DIR} is missing, plus OpenBSD 7.5.
+
+@item
+The conversion macros @code{DTTOIF} and @code{IFTODT} are missing on
+many systems (however, the Gnulib replacement macros
+may evaluate their arguments multiple times):
+All systems where @code{DT_DIR} is missing, plus OpenBSD 7.5.
+
@item
The type @code{ino_t} is missing on some platforms:
glibc 2.23 and others.
@itemize
@item
Although many systems define a @code{struct dirent} member named
-@code{d_type} and directory entry type macros like @code{DT_DIR} and
-@code{DT_LNK}, some do not:
+@code{d_type}, some do not:
Minix 3.1.8, AIX 7.2, HP-UX 11, Solaris 11.4, mingw.
@item
On systems with @code{d_type}, not every filesystem supports
@code{d_type}, and those lacking support will set it to @code{DT_UNKNOWN}.
+@item
+The POSIX.1-2024 directory entry type macros @code{DT_MQ},
+@code{DT_SEM}, @code{DT_SHM} and @code{DT_TMO} are missing on many
+platforms.
+
@item
Some systems define a @code{struct dirent} member named @code{d_namlen}
containing the string length of @code{d_name}, but others do not:
char d_type;
char d_name[1];
};
-/* Possible values for 'd_type'. */
-# define DT_UNKNOWN 0
-# define DT_FIFO 1 /* FIFO */
-# define DT_CHR 2 /* character device */
-# define DT_DIR 4 /* directory */
-# define DT_BLK 6 /* block device */
-# define DT_REG 8 /* regular file */
-# define DT_LNK 10 /* symbolic link */
-# define DT_SOCK 12 /* socket */
-# define DT_WHT 14 /* whiteout */
# define GNULIB_defined_struct_dirent 1
# endif
#endif
+/* 'd_type' macros specified in GNU, i.e., POSIX.1-2024 plus DT_WHT,
+ but not (yet) DT_MQ, DT_SEM, DT_SHM, DT_TMO.
+ These macros can be useful even on platforms that do not support
+ d_type or the corresponding file types.
+ Default to the Linux values which are also popular elsewhere,
+ and check that all macros have distinct values. */
+#ifndef DT_UNKNOWN
+# define DT_UNKNOWN 0
+#endif
+#ifndef DT_FIFO
+# define DT_FIFO 1 /* FIFO */
+#endif
+#ifndef DT_CHR
+# define DT_CHR 2 /* character device */
+#endif
+#ifndef DT_DIR
+# define DT_DIR 4 /* directory */
+#endif
+#ifndef DT_BLK
+# define DT_BLK 6 /* block device */
+#endif
+#ifndef DT_REG
+# define DT_REG 8 /* regular file */
+#endif
+#ifndef DT_LNK
+# define DT_LNK 10 /* symbolic link */
+#endif
+#ifndef DT_SOCK
+# define DT_SOCK 12 /* socket */
+#endif
+#ifndef DT_WHT
+# define DT_WHT 14 /* whiteout */
+#endif
+static_assert (DT_UNKNOWN != DT_FIFO && DT_UNKNOWN != DT_CHR
+ && DT_UNKNOWN != DT_BLK && DT_UNKNOWN != DT_REG
+ && DT_UNKNOWN != DT_LNK && DT_UNKNOWN != DT_SOCK
+ && DT_UNKNOWN != DT_WHT
+ && DT_FIFO != DT_CHR && DT_FIFO != DT_BLK && DT_FIFO != DT_REG
+ && DT_FIFO != DT_LNK && DT_FIFO != DT_SOCK && DT_FIFO != DT_WHT
+ && DT_CHR != DT_BLK && DT_CHR != DT_REG && DT_CHR != DT_LNK
+ && DT_CHR != DT_SOCK && DT_CHR != DT_WHT
+ && DT_BLK != DT_REG && DT_BLK != DT_LNK && DT_BLK != DT_SOCK
+ && DT_BLK != DT_WHT
+ && DT_REG != DT_LNK && DT_REG != DT_SOCK && DT_REG != DT_WHT
+ && DT_LNK != DT_SOCK && DT_LNK != DT_WHT
+ && DT_SOCK != DT_WHT);
+
+/* Conversion between S_IF* and DT_* file types. */
+#if ! (defined IFTODT && defined DTTOIF)
+# include <sys/stat.h>
+# ifdef S_ISWHT
+# define _GL_DIRENT_S_ISWHT(mode) S_ISWHT(mode)
+# else
+# define _GL_DIRENT_S_ISWHT(mode) 0
+# endif
+# ifdef S_IFWHT
+# define _GL_DIRENT_S_IFWHT S_IFWHT
+# else
+# define _GL_DIRENT_S_IFWHT (DT_WHT << 12) /* just a guess */
+# endif
+#endif
+#ifndef IFTODT
+# define IFTODT(mode) \
+ (S_ISREG (mode) ? DT_REG : S_ISDIR (mode) ? DT_DIR \
+ : S_ISLNK (mode) ? DT_LNK : S_ISBLK (mode) ? DT_BLK \
+ : S_ISCHR (mode) ? DT_CHR : S_ISFIFO (mode) ? DT_FIFO \
+ : S_ISSOCK (mode) ? DT_SOCK \
+ : _GL_DIRENT_S_ISWHT (mode) ? DT_WHT : DT_UNKNOWN)
+#endif
+#ifndef DTTOIF
+# define DTTOIF(dirtype) \
+ ((dirtype) == DT_REG ? S_IFREG : (dirtype) == DT_DIR ? S_IFDIR \
+ : (dirtype) == DT_LNK ? S_IFLNK : (dirtype) == DT_BLK ? S_IFBLK \
+ : (dirtype) == DT_CHR ? S_IFCHR : dirtype == DT_FIFO ? S_IFIFO \
+ : (dirtype) == DT_SOCK ? S_IFSOCK \
+ : (dirtype) == DT_WHT ? _GL_DIRENT_S_IFWHT \
+ : (dirtype) << 12 /* just a guess */)
+#endif
+
#if !@DIR_HAS_FD_MEMBER@
# if !GNULIB_defined_DIR
/* struct gl_directory is a type with a field 'int fd_to_close'.