#ifndef _DIRENT_H
#define _DIRENT_H
/*
 *      <dirent.h>
 *
 *  Definitions for file system independent directory access routines.
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  20 Jan 96   DJW   - Added dd_namelen field to 'DIR' structure to allow
 *                      for more effeciency in readdir() processing.
 */

#ifndef _SYS_TYPES_H_
#include <sys/types.h>
#endif

#ifndef _LIMITS_H
#include <limits.h>
#endif

#define d_ino d_fileno      /* For compatability */

/*
 *  POSIX structure used to define a directory entry.
 */
struct dirent {
    off_t          d_off;           /* Offset of next directory entry */
    ino_t          d_ino;           /* inode of file (not used in QDOS) */
    unsigned short d_reclen;        /* Length of this record */
    unsigned short d_namlen;        /* length of string in d_name */
    char           d_name[MAXNAMELEN + 1]; /* name (up to MAXNAMELEN+1) */
};

/*  The following give backwards compatibility with previous releases of C68 */
#define d_namelen d_namlen

/*
 *  Name of the structure used to control the directory accessing routines.
 *  Application code should never use any of the fields defined in this
 *  structure as they are all implementation defined and subject to change
 *  without notice.
 */
typedef struct _dirdesc {
    long          dd_loc;               /* Where we are in the directory */
    short         dd_namelen;           /* length of name in dd_name */
    char          dd_name[MAXNAMELEN+1];/* name of open directory */
    struct dirent dd_buf;               /* Buffer to return for readdir calls */
} DIR;

#define DIRSIZ(dp) \
    (((sizeof(struct dirent) - (MAXNAMELEN+1) + ((dp)->d_namelen))+1)&~1)

#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params) ()
#endif

int     getdents    _P_((int, struct dirent *, size_t));
int     closedir    _P_((DIR *));
DIR *   opendir     _P_((char *));
void    rewinddir   _P_((DIR *));
void    seekdir     _P_((DIR *, long));
long    telldir     _P_((DIR *));
struct dirent *readdir _P_((DIR *));

#undef _P_

#endif

