2009-03-04 04:28:35 +01:00
/*
* Copyright ( C ) 2008 The Android Open Source Project
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in
* the documentation and / or other materials provided with the
* distribution .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING ,
* BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS
* OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY ,
* OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE .
*/
2014-01-09 01:31:36 +01:00
2020-03-28 00:28:34 +01:00
# pragma once
/**
* @ file dirent . h
* @ brief Directory entry iteration .
*/
2009-03-04 04:28:35 +01:00
# include <stdint.h>
# include <sys/cdefs.h>
2017-07-05 21:34:29 +02:00
# include <sys/types.h>
2009-03-04 04:28:35 +01:00
__BEGIN_DECLS
2020-03-28 00:28:34 +01:00
/** d_type value when the type is not known. */
2014-01-09 01:31:36 +01:00
# define DT_UNKNOWN 0
2020-03-28 00:28:34 +01:00
/** d_type value for a FIFO. */
2014-01-09 01:31:36 +01:00
# define DT_FIFO 1
2020-03-28 00:28:34 +01:00
/** d_type value for a character device. */
2014-01-09 01:31:36 +01:00
# define DT_CHR 2
2020-03-28 00:28:34 +01:00
/** d_type value for a directory. */
2014-01-09 01:31:36 +01:00
# define DT_DIR 4
2020-03-28 00:28:34 +01:00
/** d_type value for a block device. */
2014-01-09 01:31:36 +01:00
# define DT_BLK 6
2020-03-28 00:28:34 +01:00
/** d_type value for a regular file. */
2014-01-09 01:31:36 +01:00
# define DT_REG 8
2020-03-28 00:28:34 +01:00
/** d_type value for a symbolic link. */
2014-01-09 01:31:36 +01:00
# define DT_LNK 10
2020-03-28 00:28:34 +01:00
/** d_type value for a socket. */
2014-01-09 01:31:36 +01:00
# define DT_SOCK 12
# define DT_WHT 14
2009-03-04 04:28:35 +01:00
2017-07-05 21:34:29 +02:00
# if defined(__LP64__)
# define __DIRENT64_INO_T ino_t
# else
# define __DIRENT64_INO_T uint64_t /* Historical accident. */
# endif
Implement some of the missing LFS64 support.
This gives us:
* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64
* <fcntl.h>
creat64, openat64, open64.
* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.
* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.
* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.
This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).
Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-01-18 03:42:49 +01:00
# define __DIRENT64_BODY \
2017-07-05 21:34:29 +02:00
__DIRENT64_INO_T d_ino ; \
off64_t d_off ; \
unsigned short d_reclen ; \
unsigned char d_type ; \
char d_name [ 256 ] ; \
Implement some of the missing LFS64 support.
This gives us:
* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64
* <fcntl.h>
creat64, openat64, open64.
* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.
* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.
* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.
This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).
Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-01-18 03:42:49 +01:00
2020-03-28 00:28:34 +01:00
/** The structure returned by readdir(). Identical to dirent64 on Android. */
Implement some of the missing LFS64 support.
This gives us:
* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64
* <fcntl.h>
creat64, openat64, open64.
* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.
* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.
* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.
This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).
Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-01-18 03:42:49 +01:00
struct dirent { __DIRENT64_BODY } ;
2020-03-28 00:28:34 +01:00
/** The structure returned by readdir64(). Identical to dirent on Android. */
Implement some of the missing LFS64 support.
This gives us:
* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64
* <fcntl.h>
creat64, openat64, open64.
* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.
* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.
* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.
This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).
Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-01-18 03:42:49 +01:00
struct dirent64 { __DIRENT64_BODY } ;
2014-05-13 12:01:11 +02:00
# undef __DIRENT64_BODY
2017-07-05 21:34:29 +02:00
# undef __DIRENT64_INO_T
2014-05-13 12:01:11 +02:00
2014-11-10 23:56:49 +01:00
/* glibc compatibility. */
# undef _DIRENT_HAVE_D_NAMLEN /* Linux doesn't have a d_namlen field. */
# define _DIRENT_HAVE_D_RECLEN
# define _DIRENT_HAVE_D_OFF
# define _DIRENT_HAVE_D_TYPE
2014-01-09 21:37:12 +01:00
# define d_fileno d_ino
2009-03-04 04:28:35 +01:00
2020-03-28 00:28:34 +01:00
/** The structure returned by opendir()/fopendir(). */
2012-10-26 05:55:23 +02:00
typedef struct DIR DIR ;
2009-03-04 04:28:35 +01:00
2020-03-28 00:28:34 +01:00
/**
* [ opendir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/opendir.3.html)
* opens a directory stream for the directory at ` __path ` .
*
* Returns null and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
DIR * _Nullable opendir ( const char * _Nonnull __path ) ;
2020-03-28 00:28:34 +01:00
/**
* [ fopendir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/opendir.3.html)
* opens a directory stream for the directory at ` __dir_fd ` .
*
* Returns null and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
DIR * _Nullable fdopendir ( int __dir_fd ) ;
2020-03-28 00:28:34 +01:00
/**
* [ readdir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/readdir.3.html)
* returns the next directory entry in the given directory .
*
* Returns a pointer to a directory entry on success ,
* or returns null and leaves ` errno ` unchanged at the end of the directory ,
* or returns null and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
struct dirent * _Nullable readdir ( DIR * _Nonnull __dir ) ;
2020-03-28 00:28:34 +01:00
/**
* [ readdir64 ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/readdir.3.html)
* returns the next directory entry in the given directory .
*
* Returns a pointer to a directory entry on success ,
* or returns null and leaves ` errno ` unchanged at the end of the directory ,
* or returns null and sets ` errno ` on failure .
*/
2023-06-16 21:39:33 +02:00
struct dirent64 * _Nullable readdir64 ( DIR * _Nonnull __dir ) ;
2020-03-28 00:28:34 +01:00
2023-03-18 00:15:17 +01:00
int readdir_r ( DIR * _Nonnull __dir , struct dirent * _Nonnull __entry , struct dirent * _Nullable * _Nonnull __buffer ) __attribute__ ( ( __deprecated__ ( " readdir_r is deprecated ; use readdir instead " )));
2023-06-16 21:39:33 +02:00
int readdir64_r ( DIR * _Nonnull __dir , struct dirent64 * _Nonnull __entry , struct dirent64 * _Nullable * _Nonnull __buffer ) __attribute__ ( ( __deprecated__ ( " readdir64_r is deprecated ; use readdir64 instead " )));
2020-03-28 00:28:34 +01:00
/**
* [ closedir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/closedir.3.html)
* closes a directory stream .
*
* Returns 0 on success and returns - 1 and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
int closedir ( DIR * _Nonnull __dir ) ;
2020-03-28 00:28:34 +01:00
/**
* [ rewinddir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/rewinddir.3.html)
* rewinds a directory stream to the first entry .
*/
2023-03-18 00:15:17 +01:00
void rewinddir ( DIR * _Nonnull __dir ) ;
2020-03-28 00:28:34 +01:00
/**
* [ seekdir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/seekdir.3.html)
* seeks a directory stream to the given entry , which must be a value returned
* by telldir ( ) .
*
* Available since API level 23.
*/
2023-03-18 00:15:17 +01:00
void seekdir ( DIR * _Nonnull __dir , long __location ) __INTRODUCED_IN ( 23 ) ;
2020-03-28 00:28:34 +01:00
/**
* [ telldir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/telldir.3.html)
* returns a value representing the current position in the directory
* for use with seekdir ( ) .
*
* Returns the current position on success and returns - 1 and sets ` errno ` on failure .
*
* Available since API level 23.
*/
2023-03-18 00:15:17 +01:00
long telldir ( DIR * _Nonnull __dir ) __INTRODUCED_IN ( 23 ) ;
2020-03-28 00:28:34 +01:00
/**
* [ dirfd ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/dirfd.3.html)
* returns the file descriptor backing the given directory stream .
*
* Returns a file descriptor on success and returns - 1 and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
int dirfd ( DIR * _Nonnull __dir ) ;
2020-03-28 00:28:34 +01:00
/**
* [ alphasort ] ( http : //man7.org/linux/man-pages/man3/alphasort.3.html) is a
* comparator for use with scandir ( ) that uses strcoll ( ) .
*/
2023-03-18 00:15:17 +01:00
int alphasort ( const struct dirent * _Nonnull * _Nonnull __lhs , const struct dirent * _Nonnull * _Nonnull __rhs ) ;
2020-03-28 00:28:34 +01:00
/**
* [ alphasort64 ] ( http : //man7.org/linux/man-pages/man3/alphasort.3.html) is a
* comparator for use with scandir64 ( ) that uses strcmp ( ) .
*/
2023-06-16 21:39:33 +02:00
int alphasort64 ( const struct dirent64 * _Nonnull * _Nonnull __lhs , const struct dirent64 * _Nonnull * _Nonnull __rhs ) ;
2020-03-28 00:28:34 +01:00
/**
* [ scandir ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/scandir.3.html)
* scans all the directory ` __path ` , filtering entries with ` __filter ` and
* sorting them with qsort ( ) using the given ` __comparator ` , and storing them
* into ` __name_list ` . Passing NULL as the filter accepts all entries .
2023-03-18 00:15:17 +01:00
* Passing NULL as the comparator skips sorting .
2020-03-28 00:28:34 +01:00
*
* Returns the number of entries returned in the list on success ,
* and returns - 1 and sets ` errno ` on failure .
*/
2023-03-18 00:15:17 +01:00
int scandir ( const char * _Nonnull __path , struct dirent * _Nonnull * _Nonnull * _Nonnull __name_list , int ( * _Nullable __filter ) ( const struct dirent * _Nonnull ) , int ( * _Nullable __comparator ) ( const struct dirent * _Nonnull * _Nonnull , const struct dirent * _Nonnull * _Nonnull ) ) ;
2015-10-27 19:10:36 +01:00
2020-03-28 00:28:34 +01:00
/**
* [ scandir64 ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/scandir.3.html)
* scans all the directory ` __path ` , filtering entries with ` __filter ` and
* sorting them with qsort ( ) using the given ` __comparator ` , and storing them
* into ` __name_list ` . Passing NULL as the filter accepts all entries .
2023-03-18 00:15:17 +01:00
* Passing NULL as the comparator skips sorting .
2020-03-28 00:28:34 +01:00
*
* Returns the number of entries returned in the list on success ,
* and returns - 1 and sets ` errno ` on failure .
*/
2023-06-16 21:39:33 +02:00
int scandir64 ( const char * _Nonnull __path , struct dirent64 * _Nonnull * _Nonnull * _Nonnull __name_list , int ( * _Nullable __filter ) ( const struct dirent64 * _Nonnull ) , int ( * _Nullable __comparator ) ( const struct dirent64 * _Nonnull * _Nonnull , const struct dirent64 * _Nonnull * _Nonnull ) ) ;
2020-03-28 00:28:34 +01:00
2015-10-27 19:10:36 +01:00
# if defined(__USE_GNU)
2020-03-28 00:28:34 +01:00
/**
* [ scandirat64 ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/scandirat.3.html)
* scans all the directory referenced by the pair of ` __dir_fd ` and ` __path ` ,
* filtering entries with ` __filter ` and sorting them with qsort ( ) using the
* given ` __comparator ` , and storing them into ` __name_list ` . Passing NULL as
* the filter accepts all entries .
2023-03-18 00:15:17 +01:00
* Passing NULL as the comparator skips sorting .
2020-03-28 00:28:34 +01:00
*
* Returns the number of entries returned in the list on success ,
* and returns - 1 and sets ` errno ` on failure .
*
* Available since API level 24.
*/
2023-03-18 00:15:17 +01:00
int scandirat64 ( int __dir_fd , const char * _Nonnull __path , struct dirent64 * _Nonnull * _Nonnull * _Nonnull __name_list , int ( * _Nullable __filter ) ( const struct dirent64 * _Nonnull ) , int ( * _Nullable __comparator ) ( const struct dirent64 * _Nonnull * _Nonnull , const struct dirent64 * _Nonnull * _Nonnull ) ) __INTRODUCED_IN ( 24 ) ;
2020-03-28 00:28:34 +01:00
/**
* [ scandirat ( 3 ) ] ( http : //man7.org/linux/man-pages/man3/scandirat.3.html)
* scans all the directory referenced by the pair of ` __dir_fd ` and ` __path ` ,
* filtering entries with ` __filter ` and sorting them with qsort ( ) using the
* given ` __comparator ` , and storing them into ` __name_list ` . Passing NULL as
* the filter accepts all entries .
2023-03-18 00:15:17 +01:00
* Passing NULL as the comparator skips sorting .
2020-03-28 00:28:34 +01:00
*
* Returns the number of entries returned in the list on success ,
* and returns - 1 and sets ` errno ` on failure .
*
* Available since API level 24.
*/
2023-03-18 00:15:17 +01:00
int scandirat ( int __dir_fd , const char * _Nonnull __path , struct dirent * _Nonnull * _Nonnull * _Nonnull __name_list , int ( * _Nullable __filter ) ( const struct dirent * _Nonnull ) , int ( * _Nullable __comparator ) ( const struct dirent * _Nonnull * _Nonnull , const struct dirent * _Nonnull * _Nonnull ) ) __INTRODUCED_IN ( 24 ) ;
2020-03-28 00:28:34 +01:00
2015-10-27 19:10:36 +01:00
# endif
2009-03-04 04:28:35 +01:00
__END_DECLS