posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
dirent.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 * Copyright (c) 2024 Tenstorrent AI ULC
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
18#ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_
19#define ZEPHYR_INCLUDE_POSIX_DIRENT_H_
20
21#include <limits.h>
22
23#include <zephyr/toolchain.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#if !defined(NAME_MAX) && defined(_XOPEN_SOURCE)
31#define NAME_MAX _XOPEN_NAME_MAX
32#endif
33
34#if !defined(NAME_MAX) && defined(_POSIX_C_SOURCE)
36#define NAME_MAX _POSIX_NAME_MAX
37#endif
38
40typedef void DIR;
41
43struct dirent {
44 unsigned int d_ino;
45 char d_name[NAME_MAX + 1];
46};
47
48#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
57int alphasort(const struct dirent **d1, const struct dirent **d2);
58#endif
59
67int closedir(DIR *dirp);
68
69#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
77int dirfd(DIR *dirp);
78#endif
79
87DIR *fdopendir(int fd);
88
96DIR *opendir(const char *dirname);
97
104struct dirent *readdir(DIR *dirp);
105
106#if (_POSIX_C_SOURCE >= 199506L) || (_XOPEN_SOURCE >= 500)
116int readdir_r(DIR *ZRESTRICT dirp, struct dirent *ZRESTRICT entry,
117 struct dirent **ZRESTRICT result);
118#endif
119
126void rewinddir(DIR *dirp);
127
128#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
139int scandir(const char *dir, struct dirent ***namelist, int (*sel)(const struct dirent *),
140 int (*compar)(const struct dirent **, const struct dirent **));
141#endif
142
143#if defined(_XOPEN_SOURCE)
151void seekdir(DIR *dirp, long loc);
152
160long telldir(DIR *dirp);
161#endif
162
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */
long telldir(DIR *dirp)
Get the current position of a directory stream (XSI extension).
DIR * fdopendir(int fd)
Open a directory stream for a directory identified by a file descriptor.
int alphasort(const struct dirent **d1, const struct dirent **d2)
Compare two directory entries alphabetically (for use with scandir()).
void DIR
Opaque directory stream type.
Definition dirent.h:40
int readdir_r(DIR *ZRESTRICT dirp, struct dirent *ZRESTRICT entry, struct dirent **ZRESTRICT result)
Read a directory entry into a caller-supplied buffer (thread-safe).
void seekdir(DIR *dirp, long loc)
Set the position of a directory stream (XSI extension).
struct dirent * readdir(DIR *dirp)
Read the next entry from a directory stream.
int dirfd(DIR *dirp)
Get the file descriptor for an open directory stream.
int closedir(DIR *dirp)
Close a directory stream.
#define NAME_MAX
Maximum length of a file name component (XSI).
Definition dirent.h:31
int scandir(const char *dir, struct dirent ***namelist, int(*sel)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
Scan a directory, optionally filtering and sorting the entries.
void rewinddir(DIR *dirp)
Reset a directory stream to the beginning.
DIR * opendir(const char *dirname)
Open a directory stream for a named directory.
Directory entry returned by readdir().
Definition dirent.h:43
char d_name[_XOPEN_NAME_MAX+1]
Filename (null-terminated).
Definition dirent.h:45
unsigned int d_ino
File serial number.
Definition dirent.h:44