home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / h / dirent < prev    next >
Encoding:
Text File  |  2006-09-17  |  5.3 KB  |  187 lines

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