home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / h / dirent < prev    next >
Encoding:
Text File  |  2004-09-05  |  4.8 KB  |  167 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/dirent.h,v $
  4.  * $Date: 2004/04/12 13:03:37 $
  5.  * $Revision: 1.8 $
  6.  * $State: Exp $
  7.  * $Author: nick $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* POSIX Standard 5.1.2: Directory Operations <dirent.h> */
  12.  
  13. #ifndef __DIRENT_H
  14. #define __DIRENT_H
  15.  
  16. #ifndef __UNIXLIB_FEATURES_H
  17. #include <unixlib/features.h>
  18. #endif
  19.  
  20. #define __need_size_t
  21. #include <stddef.h>
  22.  
  23. #ifndef __UNIXLIB_TYPES_H
  24. #include <unixlib/types.h>
  25. #endif
  26.  
  27. __BEGIN_DECLS
  28.  
  29. #define MAXNAMLEN 255
  30.  
  31. /* This isn't really how ADFS stores files in a directory, but
  32.    since no I/O is permitted on directories anyway this doesn't
  33.    really matter.  */
  34.  
  35. struct dirent
  36. {
  37.   __ino_t    d_fileno;        /* file number of entry */
  38.   size_t    d_namlen;        /* length of d_name */
  39.   unsigned char d_type;            /* file type, possibly unknown */
  40.  
  41.   /* FIXME:  Should be a macro constant, but causing difficulties
  42.      with namespace at the moment.  */
  43.   char        d_name[256];    /* name */
  44. };
  45.  
  46. /* For backwards compatibility with BSD.  */
  47. #define d_ino    d_fileno
  48.  
  49. /* BSD file types for d_type.  */
  50. enum
  51.   {
  52.     DT_UNKNOWN = 0,
  53.     DT_FIFO = 1,
  54.     DT_CHR = 2,
  55.     DT_DIR = 4,
  56.     DT_BLK = 6,
  57.     DT_REG = 8,
  58.     DT_LNK = 10,
  59.     DT_SOCK = 12
  60.   };
  61.  
  62. /* BSD macros to convert between stat structure types and
  63.    directory types.  */
  64. #define IFTODT(mode) (((mode) & 0170000) >> 12)
  65. #define DTTOIF(dirtype) ((dirtype) << 12)
  66.  
  67. typedef struct __dir_stream DIR;
  68.  
  69. #ifdef __UNIXLIB_INTERNALS
  70.  
  71. /* Magic number to fill __magic.  */
  72. #define _DIRMAGIC 0xf7b2bace
  73.  
  74. typedef struct
  75. {
  76.   __uint32_t load_address;
  77.   __uint32_t exec_address;
  78.   __uint32_t length;
  79.   __uint32_t file_attrib;
  80.   __uint32_t obj_type;
  81.   const char obj_name[1];
  82. } __os_gbpb_10;
  83.  
  84. struct __dir_stream
  85. {
  86.   unsigned int __magic; /* magic number to protect our streams */
  87.   DIR *next;
  88.   DIR *suffix; /* used when doing reverse suffix dir mapping.  */
  89.   __off_t dd_suf_off; /* start offset used in suffix dir.  */
  90.  
  91.   char *dd_name_can; /* canonicalised name (riscos format) */
  92.  
  93.   __off_t dd_off; /* offset of next read (used for seeking) */
  94.   __off_t gbpb_off; /* offset used for os_gbpb */
  95.   __os_gbpb_10 *dir_cache; /* pointer to a cache of directory filenames */
  96.   __os_gbpb_10 *dir_cache_index; /* index in that cache for the next file  */
  97.   __u_int do_read; /* zero if we need to fill the directory cache */
  98.  
  99.   struct dirent dirent; /* last directory entry read using readdir */
  100. };
  101.  
  102. #if __INTEGRITY_CHECK
  103. /* Nonzero if stream is a valid stream.  */
  104. #define __validdir(stream) (stream != NULL && stream->__magic == _DIRMAGIC)
  105. #else
  106. #define __validdir(stream) (1)
  107. #endif
  108.  
  109. #endif /* __UNIXLIB_INTERNALS */
  110.  
  111. /* Open a directory stream on name. Return a dir stream on
  112.    the directory, or NULL if it could not be opened.  */
  113. extern DIR *opendir (const char *__name) __THROW;
  114.  
  115. /* Read a directory entry from dirp.
  116.    Return a pointer to a struct dirent describing the entry,
  117.    or NULL for EOF or error.  The storage returned may be overwritten
  118.    by a later readdir call on the same DIR stream, or by closedir.  */
  119. extern struct dirent *readdir (DIR *__dirp) __THROW;
  120.  
  121. /* Reentrant version of readdir.  */
  122. extern int readdir_r (DIR *__restrict __dirp,
  123.               struct dirent *__restrict __entry,
  124.               struct dirent **__restrict __result) __THROW;
  125.  
  126. /* Return the current position of dirp.  */
  127. extern __off_t telldir (DIR *__dirp) __THROW;
  128.  
  129. /* Seek to position pos on dirp.  */
  130. extern void seekdir (DIR *__dirp, __off_t __pos) __THROW;
  131.  
  132. /* Rewind DIRP to the beginning of the directory.  */
  133. extern void rewinddir (DIR *__dirp) __THROW;
  134.  
  135. /* Close the directory stream dirp. Return 0 if successful,
  136.    -1 if not.  */
  137. extern int closedir (DIR *__dirp) __THROW;
  138.  
  139. /* Function to compare two `struct dirent's alphabetically.  */
  140. extern int alphasort (const struct dirent **__a,
  141.               const struct dirent ** __b) __THROW;
  142.  
  143. /* Scan the directory dir, calling 'select' on each directory entry.
  144.    Entries for which 'select' returns nonzero are individually malloc'd,
  145.    sorted using qsort with 'cmp', and collected in a malloc'd array in
  146.    *namelist.  Returns the number of entries selected, or -1 on error.  */
  147.  
  148. extern int scandir (const char *__restrict __dir,
  149.             struct dirent ***__restrict __namelist,
  150.             int (*__select)(const struct dirent *),
  151.             int (*__cmp)(const struct dirent **,
  152.                  const struct dirent **)) __THROW;
  153.  
  154. #if 0
  155. /* Read directory entries from fd into buf, reading at most nbytes.
  156.    Reading starts at offset *basep, and *basep is updated with the new
  157.    position after reading.  Returns the number of bytes read; zero when at
  158.    end of directory; or -1 for errors.  */
  159. extern ssize_t getdirentries (int __fd, char *__restrict __buf,
  160.                   size_t __nbytes,
  161.                   __off_t *__restrict __basep) __THROW;
  162. #endif
  163.  
  164. __END_DECLS
  165.  
  166. #endif
  167.