POSIX-standard APIs for managing the filesystem
More...
|
file | libgen.h |
| Definitions for pattern matching functions.
|
|
file | dirent.h |
| Directory entry functionality.
|
|
file | uio.h |
| Header for terminal control operations.
|
|
file | termios.h |
| Header for terminal I/O control.
|
|
|
char * | basename (char *path) |
| Get the last component of a pathname.
|
|
char * | dirname (char *path) |
| Get the parent directory of a file pathname.
|
|
DIR * | opendir (const char *name) |
| Open a directory based on the specified name.
|
|
int | closedir (DIR *dir) |
| Closes a directory that was previously opened.
|
|
struct dirent * | readdir (DIR *dir) |
| Read an entry from a directory stream.
|
|
int | dirfd (DIR *dirp) |
| Retrieve the file descriptor of an opened directory stream.
|
|
void | rewinddir (DIR *dir) |
| Rewind a directory stream to the start of the directory.
|
|
int | scandir (const char *__RESTRICT dir, struct dirent ***__RESTRICT namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **)) |
| Scan, filter, and sort files within a directory.
|
|
int | alphasort (const struct dirent **a, const struct dirent **b) |
| Comparison function for sorting directory entries alphabetically.
|
|
void | seekdir (DIR *dir, off_t offset) |
| Not implemented.
|
|
off_t | telldir (DIR *dir) |
| Not implemented.
|
|
|
POSIX file types for dirent::d_type
- Todo
- Ensure each VFS driver maps its directory types accordingly
|
#define | DT_UNKNOWN 0 |
| Unknown.
|
|
#define | DT_FIFO 1 |
| Named Pipe or FIFO.
|
|
#define | DT_CHR 2 |
| Character Device.
|
|
#define | DT_DIR 4 |
| Directory.
|
|
#define | DT_BLK 6 |
| Block Device.
|
|
#define | DT_REG 8 |
| Regular File.
|
|
#define | DT_LNK 10 |
| Symbolic Link.
|
|
#define | DT_SOCK 12 |
| Local-Domain Socket.
|
|
#define | DT_WHT 14 |
| Whiteout (ignored)
|
|
POSIX-standard APIs for managing the filesystem
◆ DT_BLK
◆ DT_CHR
◆ DT_DIR
◆ DT_FIFO
◆ DT_LNK
◆ DT_REG
◆ DT_SOCK
◆ DT_UNKNOWN
◆ DT_WHT
◆ UIO_MAXIOV
Old alias for the maximum length of an iovec.
◆ alphasort()
int alphasort |
( |
const struct dirent ** | a, |
|
|
const struct dirent ** | b ) |
Comparison function for sorting directory entries alphabetically.
Sorts two directory entries, a
and b
in alphabetical order.
- Note
- This function can be used as the comparison callback passed to scandir(), to sort the returned list of entries in alphabetical order.
- Parameters
-
a | The first directory entry to sort |
b | The second directory entry to sort |
- Return values
-
Returns | an integer value greater than, equal to, or less than zero, depending on whether the name of the directory entry pointed to by a is lexically greater than, equal to, or less than the directory entry pointed to by b . |
- See also
- scandir()
◆ basename()
char * basename |
( |
char * | path | ) |
|
Get the last component of a pathname.
This function retrieves the basename from a given path. The basename of a path is the non-directory component thereof, minus any trailing '/' characters. This function does not attempt to perform any sort of path resolution.
- Note
- This function may modify its input and the returned value may be a pointer to part of its input.
- Parameters
-
path | The path to extract the basename from. |
- Returns
- A pointer to the basename of the given path.
◆ closedir()
int closedir |
( |
DIR * | dir | ) |
|
Closes a directory that was previously opened.
This function is used to close a directory stream that was previously opened with the opendir() function. You must do this to clean up any resources associated with the directory stream.
- Parameters
-
dir | The directory stream to close. |
- Returns
- 0 on success. -1 on error, setting errno as appropriate.
◆ dirfd()
Retrieve the file descriptor of an opened directory stream.
This function retrieves the file descriptor of a directory stream that was previously opened with opendir().
- Warning
- Do not close() the returned file descriptor. It will be closed when closedir() is called on the directory stream.
- Parameters
-
dirp | The directory stream to retrieve the descriptor of. |
- Returns
- The file descriptor from the directory stream on success or -1 on failure (sets errno as appropriate).
◆ dirname()
char * dirname |
( |
char * | path | ) |
|
Get the parent directory of a file pathname.
This function retrieves the name of the parent directory of the file pathname specified. This function does not attempt to perform any sort of path resolution to check for the existence of the specified directory or to resolve any symbolic links.
- Note
- This function may modify its input and the returned value may be a pointer to part of its input.
- Parameters
-
path | The path to extract the parent directory from. |
- Returns
- A pointer to the parent directory of the given path.
◆ opendir()
DIR * opendir |
( |
const char * | name | ) |
|
Open a directory based on the specified name.
The directory specified is opened if it exists. A directory stream object is returned for accessing the entries of the directory.
- Note
- As with other functions for opening files on the VFS, relative paths are permitted for the name parameter of this function.
- Parameters
-
name | The name of the directory to open. |
- Returns
- A directory stream object to be used with readdir() on success, NULL on failure. Sets errno as appropriate.
- See also
- closedir
-
readdir
◆ readdir()
Read an entry from a directory stream.
This function reads the next entry from the directory stream provided, returning the directory entry associated with the next object in the directory.
- Warning
- Do not free the returned dirent!
- Parameters
-
dir | The directory stream to read from. |
- Returns
- A pointer to the next directory entry in the directory or NULL if there are no other entries in the directory. If an error is incurred, NULL will be returned and errno set to indicate the error.
◆ rewinddir()
void rewinddir |
( |
DIR * | dir | ) |
|
Rewind a directory stream to the start of the directory.
This function rewinds the directory stream so that the next call to the readdir() function will return the first entry in the directory.
- Warning
- Some filesystems do not support this call. Notably, none of the dcload filesystems support it. Error values will be returned in errno (so set errno to 0, then check after calling the function to see if there was a problem anywhere).
- Parameters
-
dir | The directory stream to rewind. |
◆ scandir()
Scan, filter, and sort files within a directory.
This function scans through all files within the directory located at the path given by dir
, calling filter
on each entry. Entries for which filter
returns nonzero are stored within namelist
and are sorted using qsort() with the comparison function, compar
. The resulting directory entries are accumulated and stored witin namelist
.
- Note
filter
and compar
may be NULL, if you do not wish to filter or sort the files.
- Warning
- The entries within
namelist
are each independently heap-allocated, then the list itself heap allocated, so each entry must be freed within the list followed by the list itself.
- Parameters
-
dir | The path to the directory to scan |
namelist | A pointer through which the list of entries will be returned. |
filter | The callback used to filter each directory entry (returning 1 for inclusion, 0 for exclusion). |
compar | The callback passed to qsort() to sort namelist by |
- Return values
-
>=0 | On success, the number of directory entries within namelist is returned |
-1 | On failure, -1 is returned and errno is set |
- See also
- alphasort
◆ seekdir()
void seekdir |
( |
DIR * | dir, |
|
|
off_t | offset ) |
◆ telldir()
off_t telldir |
( |
DIR * | dir | ) |
|