KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches

POSIX-standard APIs for managing the filesystem. More...

Files

file  libgen.h
 Definitions for pattern matching functions.
 
file  dirent.h
 Directory entry functionality.
 
file  uio.h
 Header for vector I/O.
 

Data Structures

struct  dirent
 POSIX directory entry structure. More...
 
struct  DIR
 Type representing a directory stream. More...
 
struct  iovec_t
 I/O vector structure. More...
 

Macros

#define UIO_MAXIOV   IOV_MAX
 Old alias for the maximum length of an iovec.
 

Functions

char * basename (char *path)
 Get the last component of a pathname.
 
char * dirname (char *path)
 Get the parent directory of a file pathname.
 
DIRopendir (const char *name)
 Open a directory based on the specified name.
 
int closedir (DIR *dir)
 Closes a directory that was previously opened.
 
struct direntreaddir (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.
 

Directory File Types

POSIX file types for dirent::d_name

Remarks
These directory entry types are not part of the POSIX specifican per-se, but are used by BSD and glibc.
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)
 

Detailed Description

POSIX-standard APIs for managing the filesystem.

Macro Definition Documentation

◆ DT_BLK

#define DT_BLK   6

Block Device.

◆ DT_CHR

#define DT_CHR   2

Character Device.

◆ DT_DIR

#define DT_DIR   4

Directory.

◆ DT_FIFO

#define DT_FIFO   1

Named Pipe or FIFO.

◆ DT_LNK

#define DT_LNK   10

Symbolic Link.

◆ DT_REG

#define DT_REG   8

Regular File.

◆ DT_SOCK

#define DT_SOCK   12

Local-Domain Socket.

◆ DT_UNKNOWN

#define DT_UNKNOWN   0

Unknown.

◆ DT_WHT

#define DT_WHT   14

Whiteout (ignored)

◆ UIO_MAXIOV

#define UIO_MAXIOV   IOV_MAX

Old alias for the maximum length of an iovec.

Function Documentation

◆ 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
aThe first directory entry to sort
bThe second directory entry to sort
Return values
Returnsan 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
pathThe 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
dirThe directory stream to close.
Returns
0 on success. -1 on error, setting errno as appropriate.

◆ dirfd()

int dirfd ( DIR dirp)

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
dirpThe 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
pathThe 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
nameThe 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()

struct dirent * readdir ( DIR dir)

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
dirThe 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
dirThe directory stream to rewind.

◆ scandir()

int scandir ( const char *__RESTRICT  dir,
struct dirent ***__RESTRICT  namelist,
int(*)(const struct dirent *)  filter,
int(*)(const struct dirent **, const struct dirent **)  compar 
)

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
dirThe path to the directory to scan
namelistA pointer through which the list of entries will be returned.
filterThe callback used to filter each directory entry (returning 1 for inclusion, 0 for exclusion).
comparThe callback passed to qsort() to sort namelist by
Return values
>=0On success, the number of directory entries within namelist is returned
-1On failure, -1 is returned and errno is set
See also
alphasort

◆ seekdir()

void seekdir ( DIR dir,
off_t  offset 
)

Not implemented.

◆ telldir()

off_t telldir ( DIR dir)

Not implemented.