home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_clib_h_dirent < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  4.2 KB  |  151 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/clib/h/RCS/dirent,v $
  4.  * $Date: 1996/11/06 22:01:41 $
  5.  * $Revision: 1.3 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: dirent,v $
  10.  * Revision 1.3  1996/11/06 22:01:41  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.2  1996/10/30 21:58:58  unixlib
  14.  * Massive changes made by Nick Burret and Peter Burwood.
  15.  *
  16.  * Revision 1.1  1996/04/19 21:02:57  simon
  17.  * Initial revision
  18.  *
  19.  ***************************************************************************/
  20.  
  21. /* POSIX Standard 5.1.2: Directory Operations <dirent.h> */
  22.  
  23. #ifndef __DIRENT_H
  24. #define __DIRENT_H
  25.  
  26. #ifndef __STDDEF_H
  27. #include <stddef.h>
  28. #endif
  29. #ifndef __UNIXLIB_TYPES_H
  30. #include <unixlib/types.h>
  31. #endif
  32. #ifndef __SYS_PARAM_H
  33. #include <sys/param.h>
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. /* MAXNAMELEN is the BSD name for what POSIX calls NAME_MAX.  */
  41.  
  42. /* Don't assume ADFS filename restrictions.
  43.    Keep in sync with <limits.h>, _POSIX_NAME_MAX.  */
  44. #define MAXNAMLEN    MAXPATHLEN
  45.  
  46. /* This isn't really how ADFS stores files in a directory, but
  47.  * since no I/O is permitted on directories anyway this doesn't
  48.  * really matter. */
  49.  
  50.  
  51. struct    dirent
  52.   {
  53.   __off_t     d_off;        /* offset of next disk directory entry */
  54.   __ino_t     d_fileno;        /* file number of entry */
  55.   size_t    d_reclen;        /* length of this record */
  56.   size_t    d_namlen;        /* length of d_name */
  57.   unsigned char d_type;            /* file type, possibly unknown */
  58.   char        d_name[MAXNAMLEN];    /* name */
  59.   };
  60.  
  61. /* For backwards compatibility with BSD.  */
  62. #define d_ino    d_fileno
  63.  
  64. /* BSD file types for d_type.  */
  65. enum
  66.   {
  67.     DT_UNKNOWN = 0,
  68.     DT_FIFO = 1,
  69.     DT_CHR = 2,
  70.     DT_DIR = 4,
  71.     DT_BLK = 6,
  72.     DT_REG = 8,
  73.     DT_LNK = 10,
  74.     DT_SOCK = 12
  75.   };
  76.  
  77. /* BSD macros to convert between stat structure types and
  78.    directory types.  */
  79. #define IFTODT(mode) (((mode) & 0170000) >> 12)
  80. #define DTTOIF(dirtype) ((dirtype) << 12)
  81.  
  82.  
  83. #define DIRSIZ(dp) (((sizeof(struct dirent) - \
  84.     MAXNAMLEN + ((dp)->d_namlen + 1)) + \
  85.     (sizeof(int) - 1)) & ~(sizeof(int) - 1))
  86.  
  87. typedef struct
  88.   {
  89.   int        dd_fd;        /* file descriptor (unused) */
  90.   char        *dd_name;    /* directory name */
  91.   size_t    dd_loc;     /* buffer offset */
  92.   size_t    dd_size;    /* amount of valid data in buffer */
  93.   size_t    dd_bsize;    /* buffer size */
  94.   size_t    dd_off;     /* directory offset */
  95.   int        dd_off2;    /* offset of next read */
  96.   char        *dd_buf;    /* directory data buffer */
  97.   } __DIR;
  98.  
  99. #define DIR __DIR
  100.  
  101. /* Open a directory stream on name. Return a dir stream on
  102.    the directory, or NULL if it could not be opened.  */
  103. extern DIR *opendir (const char *name);
  104.  
  105. /* Read a directory entry from dirp.
  106.    Return a pointer to a struct dirent describing the entry,
  107.    or NULL for EOF or error.  The storage returned may be overwritten
  108.    by a later readdir call on the same DIR stream.  */
  109. extern struct dirent *readdir (DIR *dirp);
  110.  
  111. /* Return the current position of dirp.  */
  112. extern long telldir (DIR *dirp);
  113.  
  114. /* Seek to position pos on dirp.  */
  115. extern void seekdir (DIR *dirp, __off_t pos);
  116.  
  117. /* Rewind DIRP to the beginning of the directory.  */
  118. #define rewinddir(d) (seekdir((d),(long)0),0)
  119. extern void (rewinddir)(DIR *dirp);
  120.  
  121. /* Close the directory stream dirp. Return 0 if successful,
  122.    -1 if not.  */
  123. extern int closedir (DIR *dirp);
  124.  
  125. /* Function to compare two `struct dirent's alphabetically.  */
  126. extern int alphasort (const ptr_t, const ptr_t);
  127.  
  128. #if 0
  129. /* Scan the directory dir, calling 'select' on each directory entry.
  130.    Entries for which 'select' returns nonzero are individually malloc'd,
  131.    sorted using qsort with 'cmp', and collected in a malloc'd array in
  132.    *namelist.  Returns the number of entries selected, or -1 on error.  */
  133. extern int scandir (const char *dir,
  134.                       struct dirent ***namelist,
  135.             int (*select) (struct dirent *),
  136.             int (*cmp) (const ptr_t, const ptr_t));
  137.  
  138. /* Read directory entries from fd into buf, reading at most nbytes.
  139.    Reading starts at offset *basep, and *basep is updated with the new
  140.    position after reading.  Returns the number of bytes read; zero when at
  141.    end of directory; or -1 for errors.  */
  142. extern ssize_t getdirentries (int fd, char *buf,
  143.                   size_t nbytes, __off_t *basep);
  144. #endif
  145.  
  146. #ifdef __cplusplus
  147.     }
  148. #endif
  149.  
  150. #endif
  151.