#ifndef _DIRENT_H
#define _DIRENT_H

#include <luna/os-limits.h>
#include <sys/types.h>

/* An entry in a directory. */
struct dirent
{
    ino_t d_ino;
    off_t d_off;
    unsigned short d_reclen;
    unsigned char d_type;
    char d_name[NAME_MAX];
};

/* A stream representing a directory. */
typedef struct
{
    int d_dirfd;
} DIR;

#ifdef __cplusplus
extern "C"
{
#endif

    /* Opens the directory at path and returns a handle to it, or NULL on error. */
    DIR* opendir(const char* path);

    /* Returns a new directory handle associated with the file descriptor fd. */
    DIR* fdopendir(int fd);

    /* Closes the directory stream. */
    int closedir(DIR* stream);

    /* Reads an entry from the directory stream. The contents of the pointer returned may be overwritten by subsequent
     * calls to readdir(). */
    struct dirent* readdir(DIR* stream);

    /* Returns the file descriptor associated with stream. */
    int dirfd(DIR* stream);

    /* Positions stream's offset at the start of the directory. */
    void rewinddir(DIR* stream);

    /* Returns the current offset position for stream. */
    long telldir(DIR* stream);

    /* Moves stream's read offset to offset, which should be the return value of a previous call to telldir(). */
    void seekdir(DIR* stream, long offset);

#ifdef __cplusplus
}
#endif

#endif