The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 28 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file dirent.h |
| 33 | * @brief Directory entry iteration. |
| 34 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | #include <sys/cdefs.h> |
Elliott Hughes | 414dd2d | 2024-10-16 14:48:30 +0000 | [diff] [blame] | 37 | |
| 38 | #include <stdint.h> |
Elliott Hughes | 0af3e8f | 2017-07-05 12:34:29 -0700 | [diff] [blame] | 39 | #include <sys/types.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | |
| 41 | __BEGIN_DECLS |
| 42 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 43 | /** d_type value when the type is not known. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 44 | #define DT_UNKNOWN 0 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 45 | /** d_type value for a FIFO. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 46 | #define DT_FIFO 1 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 47 | /** d_type value for a character device. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 48 | #define DT_CHR 2 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 49 | /** d_type value for a directory. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 50 | #define DT_DIR 4 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 51 | /** d_type value for a block device. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 52 | #define DT_BLK 6 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 53 | /** d_type value for a regular file. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 54 | #define DT_REG 8 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 55 | /** d_type value for a symbolic link. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 56 | #define DT_LNK 10 |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 57 | /** d_type value for a socket. */ |
Elliott Hughes | 38f0ef3 | 2014-01-08 16:31:36 -0800 | [diff] [blame] | 58 | #define DT_SOCK 12 |
| 59 | #define DT_WHT 14 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 60 | |
Elliott Hughes | 0af3e8f | 2017-07-05 12:34:29 -0700 | [diff] [blame] | 61 | #if defined(__LP64__) |
| 62 | #define __DIRENT64_INO_T ino_t |
| 63 | #else |
| 64 | #define __DIRENT64_INO_T uint64_t /* Historical accident. */ |
| 65 | #endif |
| 66 | |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 67 | #define __DIRENT64_BODY \ |
Elliott Hughes | 0af3e8f | 2017-07-05 12:34:29 -0700 | [diff] [blame] | 68 | __DIRENT64_INO_T d_ino; \ |
| 69 | off64_t d_off; \ |
| 70 | unsigned short d_reclen; \ |
| 71 | unsigned char d_type; \ |
| 72 | char d_name[256]; \ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 73 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 74 | /** The structure returned by readdir(). Identical to dirent64 on Android. */ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 75 | struct dirent { __DIRENT64_BODY }; |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 76 | /** The structure returned by readdir64(). Identical to dirent on Android. */ |
Elliott Hughes | db1ea34 | 2014-01-17 18:42:49 -0800 | [diff] [blame] | 77 | struct dirent64 { __DIRENT64_BODY }; |
| 78 | |
Calin Juravle | f963da2 | 2014-05-13 11:01:11 +0100 | [diff] [blame] | 79 | #undef __DIRENT64_BODY |
Elliott Hughes | 0af3e8f | 2017-07-05 12:34:29 -0700 | [diff] [blame] | 80 | #undef __DIRENT64_INO_T |
Calin Juravle | f963da2 | 2014-05-13 11:01:11 +0100 | [diff] [blame] | 81 | |
Elliott Hughes | 8c79b4e | 2014-11-10 14:56:49 -0800 | [diff] [blame] | 82 | /* glibc compatibility. */ |
| 83 | #undef _DIRENT_HAVE_D_NAMLEN /* Linux doesn't have a d_namlen field. */ |
| 84 | #define _DIRENT_HAVE_D_RECLEN |
| 85 | #define _DIRENT_HAVE_D_OFF |
| 86 | #define _DIRENT_HAVE_D_TYPE |
| 87 | |
Elliott Hughes | a8a3178 | 2014-01-09 12:37:12 -0800 | [diff] [blame] | 88 | #define d_fileno d_ino |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 89 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 90 | /** The structure returned by opendir()/fopendir(). */ |
Elliott Hughes | 063cfb2 | 2012-10-25 20:55:23 -0700 | [diff] [blame] | 91 | typedef struct DIR DIR; |
| 92 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 93 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 94 | * [opendir(3)](https://man7.org/linux/man-pages/man3/opendir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 95 | * opens a directory stream for the directory at `__path`. |
| 96 | * |
| 97 | * Returns null and sets `errno` on failure. |
| 98 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 99 | DIR* _Nullable opendir(const char* _Nonnull __path); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 102 | * [fopendir(3)](https://man7.org/linux/man-pages/man3/opendir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 103 | * opens a directory stream for the directory at `__dir_fd`. |
| 104 | * |
| 105 | * Returns null and sets `errno` on failure. |
| 106 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 107 | DIR* _Nullable fdopendir(int __dir_fd); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 110 | * [readdir(3)](https://man7.org/linux/man-pages/man3/readdir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 111 | * returns the next directory entry in the given directory. |
| 112 | * |
| 113 | * Returns a pointer to a directory entry on success, |
| 114 | * or returns null and leaves `errno` unchanged at the end of the directory, |
| 115 | * or returns null and sets `errno` on failure. |
| 116 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 117 | struct dirent* _Nullable readdir(DIR* _Nonnull __dir); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 120 | * [readdir64(3)](https://man7.org/linux/man-pages/man3/readdir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 121 | * returns the next directory entry in the given directory. |
| 122 | * |
| 123 | * Returns a pointer to a directory entry on success, |
| 124 | * or returns null and leaves `errno` unchanged at the end of the directory, |
| 125 | * or returns null and sets `errno` on failure. |
| 126 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 127 | struct dirent64* _Nullable readdir64(DIR* _Nonnull __dir); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 128 | |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 129 | int readdir_r(DIR* _Nonnull __dir, struct dirent* _Nonnull __entry, struct dirent* _Nullable * _Nonnull __buffer) __attribute__((__deprecated__("readdir_r is deprecated; use readdir instead"))); |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 130 | int readdir64_r(DIR* _Nonnull __dir, struct dirent64* _Nonnull __entry, struct dirent64* _Nullable * _Nonnull __buffer) __attribute__((__deprecated__("readdir64_r is deprecated; use readdir64 instead"))); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 133 | * [closedir(3)](https://man7.org/linux/man-pages/man3/closedir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 134 | * closes a directory stream. |
| 135 | * |
| 136 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 137 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 138 | int closedir(DIR* _Nonnull __dir); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 141 | * [rewinddir(3)](https://man7.org/linux/man-pages/man3/rewinddir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 142 | * rewinds a directory stream to the first entry. |
| 143 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 144 | void rewinddir(DIR* _Nonnull __dir); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 145 | |
| 146 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 147 | * [seekdir(3)](https://man7.org/linux/man-pages/man3/seekdir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 148 | * seeks a directory stream to the given entry, which must be a value returned |
| 149 | * by telldir(). |
| 150 | * |
| 151 | * Available since API level 23. |
| 152 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 153 | |
| 154 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 155 | void seekdir(DIR* _Nonnull __dir, long __location) __INTRODUCED_IN(23); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 158 | * [telldir(3)](https://man7.org/linux/man-pages/man3/telldir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 159 | * returns a value representing the current position in the directory |
| 160 | * for use with seekdir(). |
| 161 | * |
| 162 | * Returns the current position on success and returns -1 and sets `errno` on failure. |
| 163 | * |
| 164 | * Available since API level 23. |
| 165 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 166 | long telldir(DIR* _Nonnull __dir) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 167 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 168 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 169 | |
| 170 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 171 | * [dirfd(3)](https://man7.org/linux/man-pages/man3/dirfd.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 172 | * returns the file descriptor backing the given directory stream. |
| 173 | * |
| 174 | * Returns a file descriptor on success and returns -1 and sets `errno` on failure. |
| 175 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 176 | int dirfd(DIR* _Nonnull __dir); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 179 | * [alphasort](https://man7.org/linux/man-pages/man3/alphasort.3.html) is a |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 180 | * comparator for use with scandir() that uses strcoll(). |
| 181 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 182 | int alphasort(const struct dirent* _Nonnull * _Nonnull __lhs, const struct dirent* _Nonnull * _Nonnull __rhs); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 185 | * [alphasort64](https://man7.org/linux/man-pages/man3/alphasort.3.html) is a |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 186 | * comparator for use with scandir64() that uses strcmp(). |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 187 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 188 | int alphasort64(const struct dirent64* _Nonnull * _Nonnull __lhs, const struct dirent64* _Nonnull * _Nonnull __rhs); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 191 | * [scandir(3)](https://man7.org/linux/man-pages/man3/scandir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 192 | * scans all the directory `__path`, filtering entries with `__filter` and |
| 193 | * sorting them with qsort() using the given `__comparator`, and storing them |
| 194 | * into `__name_list`. Passing NULL as the filter accepts all entries. |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 195 | * Passing NULL as the comparator skips sorting. |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 196 | * |
| 197 | * Returns the number of entries returned in the list on success, |
| 198 | * and returns -1 and sets `errno` on failure. |
| 199 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 200 | 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)); |
Elliott Hughes | 6331e80 | 2015-10-27 11:10:36 -0700 | [diff] [blame] | 201 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 202 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 203 | * [scandir64(3)](https://man7.org/linux/man-pages/man3/scandir.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 204 | * scans all the directory `__path`, filtering entries with `__filter` and |
| 205 | * sorting them with qsort() using the given `__comparator`, and storing them |
| 206 | * into `__name_list`. Passing NULL as the filter accepts all entries. |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 207 | * Passing NULL as the comparator skips sorting. |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 208 | * |
| 209 | * Returns the number of entries returned in the list on success, |
| 210 | * and returns -1 and sets `errno` on failure. |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 211 | */ |
Elliott Hughes | 655e430 | 2023-06-16 12:39:33 -0700 | [diff] [blame] | 212 | 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)); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 6331e80 | 2015-10-27 11:10:36 -0700 | [diff] [blame] | 214 | #if defined(__USE_GNU) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 217 | * [scandirat64(3)](https://man7.org/linux/man-pages/man3/scandirat.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 218 | * scans all the directory referenced by the pair of `__dir_fd` and `__path`, |
| 219 | * filtering entries with `__filter` and sorting them with qsort() using the |
| 220 | * given `__comparator`, and storing them into `__name_list`. Passing NULL as |
| 221 | * the filter accepts all entries. |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 222 | * Passing NULL as the comparator skips sorting. |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 223 | * |
| 224 | * Returns the number of entries returned in the list on success, |
| 225 | * and returns -1 and sets `errno` on failure. |
| 226 | * |
| 227 | * Available since API level 24. |
| 228 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 229 | |
| 230 | #if __BIONIC_AVAILABILITY_GUARD(24) |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 231 | 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); |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 232 | |
| 233 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 234 | * [scandirat(3)](https://man7.org/linux/man-pages/man3/scandirat.3.html) |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 235 | * scans all the directory referenced by the pair of `__dir_fd` and `__path`, |
| 236 | * filtering entries with `__filter` and sorting them with qsort() using the |
| 237 | * given `__comparator`, and storing them into `__name_list`. Passing NULL as |
| 238 | * the filter accepts all entries. |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 239 | * Passing NULL as the comparator skips sorting. |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 240 | * |
| 241 | * Returns the number of entries returned in the list on success, |
| 242 | * and returns -1 and sets `errno` on failure. |
| 243 | * |
| 244 | * Available since API level 24. |
| 245 | */ |
zijunzhao | 7d2df8b | 2023-03-17 23:15:17 +0000 | [diff] [blame] | 246 | 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); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 247 | #endif /* __BIONIC_AVAILABILITY_GUARD(24) */ |
| 248 | |
Elliott Hughes | 02f9f4c | 2020-03-27 16:28:34 -0700 | [diff] [blame] | 249 | |
Elliott Hughes | 6331e80 | 2015-10-27 11:10:36 -0700 | [diff] [blame] | 250 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 251 | |
| 252 | __END_DECLS |