(root)/
gettext-0.22.4/
gettext-tools/
gnulib-lib/
dirent.in.h
       1  /* A GNU-like <dirent.h>.
       2     Copyright (C) 2006-2023 Free Software Foundation, Inc.
       3  
       4     This file is free software: you can redistribute it and/or modify
       5     it under the terms of the GNU Lesser General Public License as
       6     published by the Free Software Foundation; either version 2.1 of the
       7     License, or (at your option) any later version.
       8  
       9     This file is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12     GNU Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public License
      15     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      16  
      17  #ifndef _@GUARD_PREFIX@_DIRENT_H
      18  
      19  #if __GNUC__ >= 3
      20  @PRAGMA_SYSTEM_HEADER@
      21  #endif
      22  @PRAGMA_COLUMNS@
      23  
      24  /* The include_next requires a split double-inclusion guard.  */
      25  #if @HAVE_DIRENT_H@
      26  # @INCLUDE_NEXT@ @NEXT_DIRENT_H@
      27  #endif
      28  
      29  #ifndef _@GUARD_PREFIX@_DIRENT_H
      30  #define _@GUARD_PREFIX@_DIRENT_H
      31  
      32  /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
      33     _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
      34  #if !_GL_CONFIG_H_INCLUDED
      35   #error "Please include config.h first."
      36  #endif
      37  
      38  /* Get ino_t.  Needed on some systems, including glibc 2.8.  */
      39  #include <sys/types.h>
      40  
      41  #if !@HAVE_DIRENT_H@
      42  /* Define types DIR and 'struct dirent'.  */
      43  # if !GNULIB_defined_struct_dirent
      44  struct dirent
      45  {
      46    char d_type;
      47    char d_name[1];
      48  };
      49  /* Possible values for 'd_type'.  */
      50  #  define DT_UNKNOWN 0
      51  #  define DT_FIFO    1          /* FIFO */
      52  #  define DT_CHR     2          /* character device */
      53  #  define DT_DIR     4          /* directory */
      54  #  define DT_BLK     6          /* block device */
      55  #  define DT_REG     8          /* regular file */
      56  #  define DT_LNK    10          /* symbolic link */
      57  #  define DT_SOCK   12          /* socket */
      58  #  define DT_WHT    14          /* whiteout */
      59  #  define GNULIB_defined_struct_dirent 1
      60  # endif
      61  #endif
      62  
      63  #if !@DIR_HAS_FD_MEMBER@
      64  # if !GNULIB_defined_DIR
      65  /* struct gl_directory is a type with a field 'int fd_to_close'.
      66     It is needed for implementing fdopendir().  */
      67  struct gl_directory;
      68  #  if @HAVE_DIRENT_H@
      69  #   define DIR struct gl_directory
      70  #  else
      71  typedef struct gl_directory DIR;
      72  #  endif
      73  #  define GNULIB_defined_DIR 1
      74  # endif
      75  #endif
      76  
      77  /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
      78     that can be freed by passing them as the Ith argument to the
      79     function F.  */
      80  #ifndef _GL_ATTRIBUTE_DEALLOC
      81  # if __GNUC__ >= 11
      82  #  define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
      83  # else
      84  #  define _GL_ATTRIBUTE_DEALLOC(f, i)
      85  # endif
      86  #endif
      87  
      88  /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
      89     allocated memory.  */
      90  /* Applies to: functions.  */
      91  #ifndef _GL_ATTRIBUTE_MALLOC
      92  # if __GNUC__ >= 3 || defined __clang__
      93  #  define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
      94  # else
      95  #  define _GL_ATTRIBUTE_MALLOC
      96  # endif
      97  #endif
      98  
      99  /* The __attribute__ feature is available in gcc versions 2.5 and later.
     100     The attribute __pure__ was added in gcc 2.96.  */
     101  #ifndef _GL_ATTRIBUTE_PURE
     102  # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
     103  #  define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
     104  # else
     105  #  define _GL_ATTRIBUTE_PURE /* empty */
     106  # endif
     107  #endif
     108  
     109  /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
     110  
     111  /* The definition of _GL_ARG_NONNULL is copied here.  */
     112  
     113  /* The definition of _GL_WARN_ON_USE is copied here.  */
     114  
     115  
     116  /* Declare overridden functions.  */
     117  
     118  #if @GNULIB_CLOSEDIR@
     119  # if @REPLACE_CLOSEDIR@
     120  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     121  #   undef closedir
     122  #   define closedir rpl_closedir
     123  #   define GNULIB_defined_closedir 1
     124  #  endif
     125  _GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     126  _GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
     127  # else
     128  #  if !@HAVE_CLOSEDIR@
     129  _GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     130  #  endif
     131  _GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
     132  # endif
     133  _GL_CXXALIASWARN (closedir);
     134  #elif defined GNULIB_POSIXCHECK
     135  # undef closedir
     136  # if HAVE_RAW_DECL_CLOSEDIR
     137  _GL_WARN_ON_USE (closedir, "closedir is not portable - "
     138                   "use gnulib module closedir for portability");
     139  # endif
     140  #endif
     141  
     142  #if @GNULIB_OPENDIR@
     143  # if @REPLACE_OPENDIR@
     144  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     145  #   undef opendir
     146  #   define opendir rpl_opendir
     147  #   define GNULIB_defined_opendir 1
     148  #  endif
     149  _GL_FUNCDECL_RPL (opendir, DIR *,
     150                    (const char *dir_name)
     151                    _GL_ARG_NONNULL ((1))
     152                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     153  _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
     154  # else
     155  #  if !@HAVE_OPENDIR@ || __GNUC__ >= 11
     156  _GL_FUNCDECL_SYS (opendir, DIR *,
     157                    (const char *dir_name)
     158                    _GL_ARG_NONNULL ((1))
     159                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     160  #  endif
     161  _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
     162  # endif
     163  _GL_CXXALIASWARN (opendir);
     164  #else
     165  # if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR && __GNUC__ >= 11 && !defined opendir
     166  /* For -Wmismatched-dealloc: Associate opendir with closedir or
     167     rpl_closedir.  */
     168  _GL_FUNCDECL_SYS (opendir, DIR *,
     169                    (const char *dir_name)
     170                    _GL_ARG_NONNULL ((1))
     171                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     172  # endif
     173  # if defined GNULIB_POSIXCHECK
     174  #  undef opendir
     175  #  if HAVE_RAW_DECL_OPENDIR
     176  _GL_WARN_ON_USE (opendir, "opendir is not portable - "
     177                   "use gnulib module opendir for portability");
     178  #  endif
     179  # endif
     180  #endif
     181  
     182  #if @GNULIB_READDIR@
     183  # if @REPLACE_READDIR@
     184  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     185  #   undef readdir
     186  #   define readdir rpl_readdir
     187  #  endif
     188  _GL_FUNCDECL_RPL (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     189  _GL_CXXALIAS_RPL (readdir, struct dirent *, (DIR *dirp));
     190  # else
     191  #  if !@HAVE_READDIR@
     192  _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     193  #  endif
     194  _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp));
     195  # endif
     196  _GL_CXXALIASWARN (readdir);
     197  #elif defined GNULIB_POSIXCHECK
     198  # undef readdir
     199  # if HAVE_RAW_DECL_READDIR
     200  _GL_WARN_ON_USE (readdir, "readdir is not portable - "
     201                   "use gnulib module readdir for portability");
     202  # endif
     203  #endif
     204  
     205  #if @GNULIB_REWINDDIR@
     206  # if @REPLACE_REWINDDIR@
     207  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     208  #   undef rewinddir
     209  #   define rewinddir rpl_rewinddir
     210  #  endif
     211  _GL_FUNCDECL_RPL (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     212  _GL_CXXALIAS_RPL (rewinddir, void, (DIR *dirp));
     213  # else
     214  #  if !@HAVE_REWINDDIR@
     215  _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1)));
     216  #  endif
     217  _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp));
     218  # endif
     219  _GL_CXXALIASWARN (rewinddir);
     220  #elif defined GNULIB_POSIXCHECK
     221  # undef rewinddir
     222  # if HAVE_RAW_DECL_REWINDDIR
     223  _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
     224                   "use gnulib module rewinddir for portability");
     225  # endif
     226  #endif
     227  
     228  #if @GNULIB_DIRFD@
     229  /* Return the file descriptor associated with the given directory stream,
     230     or -1 if none exists.  */
     231  # if @REPLACE_DIRFD@
     232  /* On kLIBC, dirfd() is a macro that does not work.  Undefine it.  */
     233  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE) || defined dirfd
     234  #   undef dirfd
     235  #   define dirfd rpl_dirfd
     236  #  endif
     237  _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
     238  _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
     239  
     240  # else
     241  #  if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
     242      /* dirfd is defined as a macro and not as a function.
     243         Turn it into a function and get rid of the macro.  */
     244  static inline int (dirfd) (DIR *dp) { return dirfd (dp); }
     245  #   undef dirfd
     246  #  endif
     247  #  if !(@HAVE_DECL_DIRFD@ || defined dirfd)
     248  _GL_FUNCDECL_SYS (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
     249  #  endif
     250  _GL_CXXALIAS_SYS (dirfd, int, (DIR *));
     251  # endif
     252  _GL_CXXALIASWARN (dirfd);
     253  #elif defined GNULIB_POSIXCHECK
     254  # undef dirfd
     255  # if HAVE_RAW_DECL_DIRFD
     256  _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
     257                   "use gnulib module dirfd for portability");
     258  # endif
     259  #endif
     260  
     261  #if @GNULIB_FDOPENDIR@
     262  /* Open a directory stream visiting the given directory file
     263     descriptor.  Return NULL and set errno if fd is not visiting a
     264     directory.  On success, this function consumes fd (it will be
     265     implicitly closed either by this function or by a subsequent
     266     closedir).  */
     267  # if @REPLACE_FDOPENDIR@
     268  #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     269  #   undef fdopendir
     270  #   define fdopendir rpl_fdopendir
     271  #  endif
     272  _GL_FUNCDECL_RPL (fdopendir, DIR *,
     273                    (int fd)
     274                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     275  _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
     276  # else
     277  #  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@ || __GNUC__ >= 11
     278  _GL_FUNCDECL_SYS (fdopendir, DIR *,
     279                    (int fd)
     280                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     281  #  endif
     282  _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
     283  # endif
     284  _GL_CXXALIASWARN (fdopendir);
     285  #else
     286  # if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined fdopendir
     287  /* For -Wmismatched-dealloc: Associate fdopendir with closedir or
     288     rpl_closedir.  */
     289  _GL_FUNCDECL_SYS (fdopendir, DIR *,
     290                    (int fd)
     291                    _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
     292  # endif
     293  # if defined GNULIB_POSIXCHECK
     294  #  undef fdopendir
     295  #  if HAVE_RAW_DECL_FDOPENDIR
     296  _GL_WARN_ON_USE (fdopendir, "fdopendir is unportable - "
     297                   "use gnulib module fdopendir for portability");
     298  #  endif
     299  # endif
     300  #endif
     301  
     302  #if @GNULIB_SCANDIR@
     303  /* Scan the directory DIR, calling FILTER on each directory entry.
     304     Entries for which FILTER returns nonzero are individually malloc'd,
     305     sorted using qsort with CMP, and collected in a malloc'd array in
     306     *NAMELIST.  Returns the number of entries selected, or -1 on error.  */
     307  # if !@HAVE_SCANDIR@
     308  _GL_FUNCDECL_SYS (scandir, int,
     309                    (const char *dir, struct dirent ***namelist,
     310                     int (*filter) (const struct dirent *),
     311                     int (*cmp) (const struct dirent **, const struct dirent **))
     312                    _GL_ARG_NONNULL ((1, 2, 4)));
     313  # endif
     314  /* Need to cast, because on glibc systems, the fourth parameter is
     315                          int (*cmp) (const void *, const void *).  */
     316  _GL_CXXALIAS_SYS_CAST (scandir, int,
     317                         (const char *dir, struct dirent ***namelist,
     318                          int (*filter) (const struct dirent *),
     319                          int (*cmp) (const struct dirent **, const struct dirent **)));
     320  _GL_CXXALIASWARN (scandir);
     321  #elif defined GNULIB_POSIXCHECK
     322  # undef scandir
     323  # if HAVE_RAW_DECL_SCANDIR
     324  _GL_WARN_ON_USE (scandir, "scandir is unportable - "
     325                   "use gnulib module scandir for portability");
     326  # endif
     327  #endif
     328  
     329  #if @GNULIB_ALPHASORT@
     330  /* Compare two 'struct dirent' entries alphabetically.  */
     331  # if !@HAVE_ALPHASORT@
     332  _GL_FUNCDECL_SYS (alphasort, int,
     333                    (const struct dirent **, const struct dirent **)
     334                    _GL_ATTRIBUTE_PURE
     335                    _GL_ARG_NONNULL ((1, 2)));
     336  # endif
     337  /* Need to cast, because on glibc systems, the parameters are
     338                         (const void *, const void *).  */
     339  _GL_CXXALIAS_SYS_CAST (alphasort, int,
     340                         (const struct dirent **, const struct dirent **));
     341  _GL_CXXALIASWARN (alphasort);
     342  #elif defined GNULIB_POSIXCHECK
     343  # undef alphasort
     344  # if HAVE_RAW_DECL_ALPHASORT
     345  _GL_WARN_ON_USE (alphasort, "alphasort is unportable - "
     346                   "use gnulib module alphasort for portability");
     347  # endif
     348  #endif
     349  
     350  
     351  #endif /* _@GUARD_PREFIX@_DIRENT_H */
     352  #endif /* _@GUARD_PREFIX@_DIRENT_H */