KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Functions
dirent.h File Reference

Directory entry functionality. More...

#include <unistd.h>
#include <arch/types.h>
#include <kos/fs.h>

Go to the source code of this file.

Data Structures

struct  dirent
 POSIX directory entry structure. More...
 
struct  DIR
 Type representing a directory stream. More...
 

Functions

DIRopendir (const char *name)
 Open a directory based on the specified name. More...
 
int closedir (DIR *dir)
 Closes a directory that was previously opened. More...
 
struct direntreaddir (DIR *dir)
 Read an entry from a directory stream. More...
 
int dirfd (DIR *dirp)
 Retrieve the file descriptor of an opened directory stream. More...
 
void rewinddir (DIR *dir)
 Rewind a directory stream to the start of the directory. More...
 
int scandir (const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
 Not implemented. More...
 
void seekdir (DIR *dir, off_t offset)
 Not implemented. More...
 
off_t telldir (DIR *dir)
 Not implemented. More...
 

Detailed Description

Directory entry functionality.

This partially implements the standard POSIX dirent.h functionality.

Author
Dan Potter

Function Documentation

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.
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().

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).
Note
Do not close() the returned file descriptor. It will be closed when closedir() is called on the directory stream.
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.

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.
Note
As with other functions for opening files on the VFS, relative paths are permitted for the name parameter of this function.
See also
closedir
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.

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.
Note
Do not free the returned dirent!
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.

Parameters
dirThe directory stream to rewind.
Note
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).
int scandir ( const char *  dir,
struct dirent ***  namelist,
int(*)(const struct dirent *)  filter,
int(*)(const struct dirent **, const struct dirent **)  compar 
)

Not implemented.

void seekdir ( DIR dir,
off_t  offset 
)

Not implemented.

off_t telldir ( DIR dir)

Not implemented.