Blame dirent/dirent.h

Packit 6c4009
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 *	POSIX Standard: 5.1.2 Directory Operations	<dirent.h>
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#ifndef	_DIRENT_H
Packit 6c4009
#define	_DIRENT_H	1
Packit 6c4009
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
__BEGIN_DECLS
Packit 6c4009
Packit 6c4009
#include <bits/types.h>
Packit 6c4009
Packit 6c4009
#ifdef __USE_XOPEN
Packit 6c4009
# ifndef __ino_t_defined
Packit 6c4009
#  ifndef __USE_FILE_OFFSET64
Packit 6c4009
typedef __ino_t ino_t;
Packit 6c4009
#  else
Packit 6c4009
typedef __ino64_t ino_t;
Packit 6c4009
#  endif
Packit 6c4009
#  define __ino_t_defined
Packit 6c4009
# endif
Packit 6c4009
# if defined __USE_LARGEFILE64 && !defined __ino64_t_defined
Packit 6c4009
typedef __ino64_t ino64_t;
Packit 6c4009
#  define __ino64_t_defined
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* This file defines `struct dirent'.
Packit 6c4009
Packit 6c4009
   It defines the macro `_DIRENT_HAVE_D_NAMLEN' iff there is a `d_namlen'
Packit 6c4009
   member that gives the length of `d_name'.
Packit 6c4009
Packit 6c4009
   It defines the macro `_DIRENT_HAVE_D_RECLEN' iff there is a `d_reclen'
Packit 6c4009
   member that gives the size of the entire directory entry.
Packit 6c4009
Packit 6c4009
   It defines the macro `_DIRENT_HAVE_D_OFF' iff there is a `d_off'
Packit 6c4009
   member that gives the file offset of the next directory entry.
Packit 6c4009
Packit 6c4009
   It defines the macro `_DIRENT_HAVE_D_TYPE' iff there is a `d_type'
Packit 6c4009
   member that gives the type of the file.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <bits/dirent.h>
Packit 6c4009
Packit 6c4009
#if defined __USE_MISC && !defined d_fileno
Packit 6c4009
# define d_ino	d_fileno		 /* Backward compatibility.  */
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* These macros extract size information from a `struct dirent *'.
Packit 6c4009
   They may evaluate their argument multiple times, so it must not
Packit 6c4009
   have side effects.  Each of these may involve a relatively costly
Packit 6c4009
   call to `strlen' on some systems, so these values should be cached.
Packit 6c4009
Packit 6c4009
   _D_EXACT_NAMLEN (DP)	returns the length of DP->d_name, not including
Packit 6c4009
   its terminating null character.
Packit 6c4009
Packit 6c4009
   _D_ALLOC_NAMLEN (DP)	returns a size at least (_D_EXACT_NAMLEN (DP) + 1);
Packit 6c4009
   that is, the allocation size needed to hold the DP->d_name string.
Packit 6c4009
   Use this macro when you don't need the exact length, just an upper bound.
Packit 6c4009
   This macro is less likely to require calling `strlen' than _D_EXACT_NAMLEN.
Packit 6c4009
   */
Packit 6c4009
Packit 6c4009
#ifdef _DIRENT_HAVE_D_NAMLEN
Packit 6c4009
# define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
Packit 6c4009
# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
Packit 6c4009
#else
Packit 6c4009
# define _D_EXACT_NAMLEN(d) (strlen ((d)->d_name))
Packit 6c4009
# ifdef _DIRENT_HAVE_D_RECLEN
Packit 6c4009
#  define _D_ALLOC_NAMLEN(d) (((char *) (d) + (d)->d_reclen) - &(d)->d_name[0])
Packit 6c4009
# else
Packit 6c4009
#  define _D_ALLOC_NAMLEN(d) (sizeof (d)->d_name > 1 ? sizeof (d)->d_name : \
Packit 6c4009
			      _D_EXACT_NAMLEN (d) + 1)
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
/* File types for `d_type'.  */
Packit 6c4009
enum
Packit 6c4009
  {
Packit 6c4009
    DT_UNKNOWN = 0,
Packit 6c4009
# define DT_UNKNOWN	DT_UNKNOWN
Packit 6c4009
    DT_FIFO = 1,
Packit 6c4009
# define DT_FIFO	DT_FIFO
Packit 6c4009
    DT_CHR = 2,
Packit 6c4009
# define DT_CHR		DT_CHR
Packit 6c4009
    DT_DIR = 4,
Packit 6c4009
# define DT_DIR		DT_DIR
Packit 6c4009
    DT_BLK = 6,
Packit 6c4009
# define DT_BLK		DT_BLK
Packit 6c4009
    DT_REG = 8,
Packit 6c4009
# define DT_REG		DT_REG
Packit 6c4009
    DT_LNK = 10,
Packit 6c4009
# define DT_LNK		DT_LNK
Packit 6c4009
    DT_SOCK = 12,
Packit 6c4009
# define DT_SOCK	DT_SOCK
Packit 6c4009
    DT_WHT = 14
Packit 6c4009
# define DT_WHT		DT_WHT
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
/* Convert between stat structure types and directory types.  */
Packit 6c4009
# define IFTODT(mode)	(((mode) & 0170000) >> 12)
Packit 6c4009
# define DTTOIF(dirtype)	((dirtype) << 12)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* This is the data type of directory stream objects.
Packit 6c4009
   The actual structure is opaque to users.  */
Packit 6c4009
typedef struct __dirstream DIR;
Packit 6c4009
Packit 6c4009
/* Open a directory stream on NAME.
Packit 6c4009
   Return a DIR stream on the directory, or NULL if it could not be opened.
Packit 6c4009
Packit 6c4009
   This function is a possible cancellation point and therefore not
Packit 6c4009
   marked with __THROW.  */
Packit 6c4009
extern DIR *opendir (const char *__name) __nonnull ((1));
Packit 6c4009
Packit 6c4009
#ifdef __USE_XOPEN2K8
Packit 6c4009
/* Same as opendir, but open the stream on the file descriptor FD.
Packit 6c4009
Packit 6c4009
   This function is a possible cancellation point and therefore not
Packit 6c4009
   marked with __THROW.  */
Packit 6c4009
extern DIR *fdopendir (int __fd);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Close the directory stream DIRP.
Packit 6c4009
   Return 0 if successful, -1 if not.
Packit 6c4009
Packit 6c4009
   This function is a possible cancellation point and therefore not
Packit 6c4009
   marked with __THROW.  */
Packit 6c4009
extern int closedir (DIR *__dirp) __nonnull ((1));
Packit 6c4009
Packit 6c4009
/* Read a directory entry from DIRP.  Return a pointer to a `struct
Packit 6c4009
   dirent' describing the entry, or NULL for EOF or error.  The
Packit 6c4009
   storage returned may be overwritten by a later readdir call on the
Packit 6c4009
   same DIR stream.
Packit 6c4009
Packit 6c4009
   If the Large File Support API is selected we have to use the
Packit 6c4009
   appropriate interface.
Packit 6c4009
Packit 6c4009
   This function is a possible cancellation point and therefore not
Packit 6c4009
   marked with __THROW.  */
Packit 6c4009
#ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern struct dirent *readdir (DIR *__dirp) __nonnull ((1));
Packit 6c4009
#else
Packit 6c4009
# ifdef __REDIRECT
Packit 6c4009
extern struct dirent *__REDIRECT (readdir, (DIR *__dirp), readdir64)
Packit 6c4009
     __nonnull ((1));
Packit 6c4009
# else
Packit 6c4009
#  define readdir readdir64
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __USE_LARGEFILE64
Packit 6c4009
extern struct dirent64 *readdir64 (DIR *__dirp) __nonnull ((1));
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __USE_POSIX
Packit 6c4009
/* Reentrant version of `readdir'.  Return in RESULT a pointer to the
Packit 6c4009
   next entry.
Packit 6c4009
Packit 6c4009
   This function is a possible cancellation point and therefore not
Packit 6c4009
   marked with __THROW.  */
Packit 6c4009
# ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern int readdir_r (DIR *__restrict __dirp,
Packit 6c4009
		      struct dirent *__restrict __entry,
Packit 6c4009
		      struct dirent **__restrict __result)
Packit 6c4009
     __nonnull ((1, 2, 3)) __attribute_deprecated__;
Packit 6c4009
# else
Packit 6c4009
#  ifdef __REDIRECT
Packit 6c4009
extern int __REDIRECT (readdir_r,
Packit 6c4009
		       (DIR *__restrict __dirp,
Packit 6c4009
			struct dirent *__restrict __entry,
Packit 6c4009
			struct dirent **__restrict __result),
Packit 6c4009
		       readdir64_r)
Packit 6c4009
  __nonnull ((1, 2, 3)) __attribute_deprecated__;
Packit 6c4009
#  else
Packit 6c4009
#   define readdir_r readdir64_r
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_LARGEFILE64
Packit 6c4009
extern int readdir64_r (DIR *__restrict __dirp,
Packit 6c4009
			struct dirent64 *__restrict __entry,
Packit 6c4009
			struct dirent64 **__restrict __result)
Packit 6c4009
  __nonnull ((1, 2, 3)) __attribute_deprecated__;
Packit 6c4009
# endif
Packit 6c4009
#endif	/* POSIX or misc */
Packit 6c4009
Packit 6c4009
/* Rewind DIRP to the beginning of the directory.  */
Packit 6c4009
extern void rewinddir (DIR *__dirp) __THROW __nonnull ((1));
Packit 6c4009
Packit 6c4009
#if defined __USE_MISC || defined __USE_XOPEN
Packit 6c4009
# include <bits/types.h>
Packit 6c4009
Packit 6c4009
/* Seek to position POS on DIRP.  */
Packit 6c4009
extern void seekdir (DIR *__dirp, long int __pos) __THROW __nonnull ((1));
Packit 6c4009
Packit 6c4009
/* Return the current position of DIRP.  */
Packit 6c4009
extern long int telldir (DIR *__dirp) __THROW __nonnull ((1));
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __USE_XOPEN2K8
Packit 6c4009
Packit 6c4009
/* Return the file descriptor used by DIRP.  */
Packit 6c4009
extern int dirfd (DIR *__dirp) __THROW __nonnull ((1));
Packit 6c4009
Packit 6c4009
# if defined __OPTIMIZE__ && defined _DIR_dirfd
Packit 6c4009
#  define dirfd(dirp)	_DIR_dirfd (dirp)
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_MISC
Packit 6c4009
#  ifndef MAXNAMLEN
Packit 6c4009
/* Get the definitions of the POSIX.1 limits.  */
Packit 6c4009
#  include <bits/posix1_lim.h>
Packit 6c4009
Packit 6c4009
/* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'.  */
Packit 6c4009
#   ifdef NAME_MAX
Packit 6c4009
#    define MAXNAMLEN	NAME_MAX
Packit 6c4009
#   else
Packit 6c4009
#    define MAXNAMLEN	255
Packit 6c4009
#   endif
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# define __need_size_t
Packit 6c4009
# include <stddef.h>
Packit 6c4009
Packit 6c4009
/* Scan the directory DIR, calling SELECTOR on each directory entry.
Packit 6c4009
   Entries for which SELECT returns nonzero are individually malloc'd,
Packit 6c4009
   sorted using qsort with CMP, and collected in a malloc'd array in
Packit 6c4009
   *NAMELIST.  Returns the number of entries selected, or -1 on error.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
# ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern int scandir (const char *__restrict __dir,
Packit 6c4009
		    struct dirent ***__restrict __namelist,
Packit 6c4009
		    int (*__selector) (const struct dirent *),
Packit 6c4009
		    int (*__cmp) (const struct dirent **,
Packit 6c4009
				  const struct dirent **))
Packit 6c4009
     __nonnull ((1, 2));
Packit 6c4009
# else
Packit 6c4009
#  ifdef __REDIRECT
Packit 6c4009
extern int __REDIRECT (scandir,
Packit 6c4009
		       (const char *__restrict __dir,
Packit 6c4009
			struct dirent ***__restrict __namelist,
Packit 6c4009
			int (*__selector) (const struct dirent *),
Packit 6c4009
			int (*__cmp) (const struct dirent **,
Packit 6c4009
				      const struct dirent **)),
Packit 6c4009
		       scandir64) __nonnull ((1, 2));
Packit 6c4009
#  else
Packit 6c4009
#   define scandir scandir64
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# if defined __USE_GNU && defined __USE_LARGEFILE64
Packit 6c4009
/* This function is like `scandir' but it uses the 64bit dirent structure.
Packit 6c4009
   Please note that the CMP function must now work with struct dirent64 **.  */
Packit 6c4009
extern int scandir64 (const char *__restrict __dir,
Packit 6c4009
		      struct dirent64 ***__restrict __namelist,
Packit 6c4009
		      int (*__selector) (const struct dirent64 *),
Packit 6c4009
		      int (*__cmp) (const struct dirent64 **,
Packit 6c4009
				    const struct dirent64 **))
Packit 6c4009
     __nonnull ((1, 2));
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_GNU
Packit 6c4009
/* Similar to `scandir' but a relative DIR name is interpreted relative
Packit 6c4009
   to the directory for which DFD is a descriptor.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
#  ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern int scandirat (int __dfd, const char *__restrict __dir,
Packit 6c4009
		      struct dirent ***__restrict __namelist,
Packit 6c4009
		      int (*__selector) (const struct dirent *),
Packit 6c4009
		      int (*__cmp) (const struct dirent **,
Packit 6c4009
				    const struct dirent **))
Packit 6c4009
     __nonnull ((2, 3));
Packit 6c4009
#  else
Packit 6c4009
#   ifdef __REDIRECT
Packit 6c4009
extern int __REDIRECT (scandirat,
Packit 6c4009
		       (int __dfd, const char *__restrict __dir,
Packit 6c4009
			struct dirent ***__restrict __namelist,
Packit 6c4009
			int (*__selector) (const struct dirent *),
Packit 6c4009
			int (*__cmp) (const struct dirent **,
Packit 6c4009
				      const struct dirent **)),
Packit 6c4009
		       scandirat64) __nonnull ((2, 3));
Packit 6c4009
#   else
Packit 6c4009
#    define scandirat scandirat64
Packit 6c4009
#   endif
Packit 6c4009
#  endif
Packit 6c4009
Packit 6c4009
/* This function is like `scandir' but it uses the 64bit dirent structure.
Packit 6c4009
   Please note that the CMP function must now work with struct dirent64 **.  */
Packit 6c4009
extern int scandirat64 (int __dfd, const char *__restrict __dir,
Packit 6c4009
			struct dirent64 ***__restrict __namelist,
Packit 6c4009
			int (*__selector) (const struct dirent64 *),
Packit 6c4009
			int (*__cmp) (const struct dirent64 **,
Packit 6c4009
				      const struct dirent64 **))
Packit 6c4009
     __nonnull ((2, 3));
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
/* Function to compare two `struct dirent's alphabetically.  */
Packit 6c4009
# ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern int alphasort (const struct dirent **__e1,
Packit 6c4009
		      const struct dirent **__e2)
Packit 6c4009
     __THROW __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
# else
Packit 6c4009
#  ifdef __REDIRECT
Packit 6c4009
extern int __REDIRECT_NTH (alphasort,
Packit 6c4009
			   (const struct dirent **__e1,
Packit 6c4009
			    const struct dirent **__e2),
Packit 6c4009
			   alphasort64) __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
#  else
Packit 6c4009
#   define alphasort alphasort64
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# if defined __USE_GNU && defined __USE_LARGEFILE64
Packit 6c4009
extern int alphasort64 (const struct dirent64 **__e1,
Packit 6c4009
			const struct dirent64 **__e2)
Packit 6c4009
     __THROW __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
# endif
Packit 6c4009
#endif /* Use XPG7.  */
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
/* Read directory entries from FD into BUF, reading at most NBYTES.
Packit 6c4009
   Reading starts at offset *BASEP, and *BASEP is updated with the new
Packit 6c4009
   position after reading.  Returns the number of bytes read; zero when at
Packit 6c4009
   end of directory; or -1 for errors.  */
Packit 6c4009
# ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern __ssize_t getdirentries (int __fd, char *__restrict __buf,
Packit 6c4009
				size_t __nbytes,
Packit 6c4009
				__off_t *__restrict __basep)
Packit 6c4009
     __THROW __nonnull ((2, 4));
Packit 6c4009
# else
Packit 6c4009
#  ifdef __REDIRECT
Packit 6c4009
extern __ssize_t __REDIRECT_NTH (getdirentries,
Packit 6c4009
				 (int __fd, char *__restrict __buf,
Packit 6c4009
				  size_t __nbytes,
Packit 6c4009
				  __off64_t *__restrict __basep),
Packit 6c4009
				 getdirentries64) __nonnull ((2, 4));
Packit 6c4009
#  else
Packit 6c4009
#   define getdirentries getdirentries64
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_LARGEFILE64
Packit 6c4009
extern __ssize_t getdirentries64 (int __fd, char *__restrict __buf,
Packit 6c4009
				  size_t __nbytes,
Packit 6c4009
				  __off64_t *__restrict __basep)
Packit 6c4009
     __THROW __nonnull ((2, 4));
Packit 6c4009
# endif
Packit 6c4009
#endif /* Use misc.  */
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* Function to compare two `struct dirent's by name & version.  */
Packit 6c4009
# ifndef __USE_FILE_OFFSET64
Packit 6c4009
extern int versionsort (const struct dirent **__e1,
Packit 6c4009
			const struct dirent **__e2)
Packit 6c4009
     __THROW __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
# else
Packit 6c4009
#  ifdef __REDIRECT
Packit 6c4009
extern int __REDIRECT_NTH (versionsort,
Packit 6c4009
			   (const struct dirent **__e1,
Packit 6c4009
			    const struct dirent **__e2),
Packit 6c4009
			   versionsort64)
Packit 6c4009
     __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
#  else
Packit 6c4009
#   define versionsort versionsort64
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_LARGEFILE64
Packit 6c4009
extern int versionsort64 (const struct dirent64 **__e1,
Packit 6c4009
			  const struct dirent64 **__e2)
Packit 6c4009
     __THROW __attribute_pure__ __nonnull ((1, 2));
Packit 6c4009
# endif
Packit 6c4009
#endif /* Use GNU.  */
Packit 6c4009
Packit 6c4009
__END_DECLS
Packit 6c4009
Packit 6c4009
#endif /* dirent.h  */