home *** CD-ROM | disk | FTP | other *** search
/ ftp.mayn.de / ftp.mayn.de-pub.zip / ftp.mayn.de-pub / apple / apple_unix / Sys_stuff / dir.h < prev    next >
C/C++ Source or Header  |  2017-03-06  |  5KB  |  180 lines

  1. #if !defined(__sys_dir_h)
  2. #define __sys_dir_h
  3.  
  4. #if !defined(_NO_IDENTS) && defined(_HEAD_IDENTS)
  5. # pragma ident "@(#)head:sys/dir.h    1.10 91/07/10 {Apple version 3.0 90/11/29 11:37:56}"
  6. #endif
  7.  
  8. /*
  9.  * Copyright 1987-91 Apple Computer, Inc.
  10.  * All Rights Reserved.
  11.  *
  12.  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF APPLE COMPUTER, INC.
  13.  * The copyright notice above does not evidence any actual or
  14.  * intended publication of such source code.
  15.  */
  16.  
  17. /* Copyright 1983-87 Sun Microsystems, Inc. */
  18. /* Copyright 1980-87 The Regents of the University of California */
  19.  
  20. /*
  21.  * [ANSI C] ANSI X3.159-1989 (3.5.4.3) Function Declarators
  22.  * [POSIX]  IEEE Std 1003.1-1988 (5.1) Directories
  23.  */
  24.  
  25. #if !defined(__sys_types_h)
  26. # if defined(__MPW_C__)
  27. #   include "/:usr:include:sys:types.h"
  28. # else
  29. #   include <sys/types.h>
  30. # endif
  31. #endif
  32.  
  33. #if defined(_BSD_SOURCE)
  34.  /*
  35.   * A directory consists of some number of blocks each of which is
  36.   * less than or equal to the filesystem block size number of
  37.   * bytes.
  38.   *
  39.   * Each block contains some number of directory entry structures,
  40.   * which are of variable length.  Each directory entry has
  41.   * a struct direct at the front of it, containing its file number,
  42.   * the length of the entry, and the length of the name contained in
  43.   * the entry.  These are followed by the name padded to a 4 byte boundary
  44.   * with null bytes.  All names are guaranteed null terminated.
  45.   * The maximum length of a name in a directory is MAXNAMLEN, plus
  46.   * a null byte.
  47.   *
  48.   * The macro DIRSIZ(dp) gives the amount of space required to represent
  49.   * a directory entry.  Free space in a directory is represented by
  50.   * entries which have dp->d_reclen > DIRSIZ(dp).
  51.   *
  52.   * All the bytes in a directory block are claimed by the directory entries.
  53.   * This usually results in the last entry in a directory having a large
  54.   * dp->d_reclen.  Free entries have their dp->d_fileno set to 0.
  55.   */
  56.  
  57. #define DIRBLKSIZ    512
  58. #define MAXNAMLEN    255
  59.  
  60. struct    direct {
  61.     u_long    d_fileno;        /* file number of entry */
  62.     u_short    d_reclen;        /* length of this record */
  63.     u_short    d_namlen;        /* length of string in d_name */
  64.     char    d_name[MAXNAMLEN + 1];    /* name (up to MAXNAMLEN + 1) */
  65. };
  66.  
  67. #if !defined(KERNEL)
  68. /*
  69.  * The DIRSIZ macro gives the minimum record length which will hold
  70.  * the directory entry.  This requires the amount of space in 'struct
  71.  * direct' without the d_name field, plus enough space for the name with
  72.  * a terminating null byte (dp->d_namlen+1), rounded up to a 4 byte
  73.  * boundary.
  74.  */
  75. #define DIRSIZ(dp) ((sizeof (struct direct) - \
  76.       (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  77.  
  78. #if !defined(NULL)
  79. #define NULL 0
  80. #endif
  81.  
  82. #endif /* !KERNEL */
  83. #endif /* _BSD_SOURCE */
  84.  
  85. #if defined(_SYSV_SOURCE) || defined(_POSIX_SOURCE)
  86. /*
  87.  * System-wide file name maximum (MAXNAMLEN isn't ANSC-compliant).
  88.  * Individual file systems (directories?) may impose smaller limits,
  89.  * e.g., System V uses 14 single-byte characters, but _SYS_NAME_MAX
  90.  * is the largest value that can be handled by the directory routines.
  91.  */
  92. #define _SYS_NAME_MAX    255
  93.  
  94. struct  dirent {
  95.     unsigned long    d_ino;            /* file number of entry */
  96.     unsigned short    d_reclen;               /* length of this record */
  97.     unsigned short    d_namlen;               /* length of string in d_name */
  98.     char    d_name[_SYS_NAME_MAX + 1];    /* name with terminating NULL */
  99. };
  100. #endif /* _SYSV_SOURCE || _POSIX_SOURCE */
  101.  
  102. /*
  103.  * Definitions for library routines operating on directories.
  104.  */
  105. typedef struct __dirdesc {
  106.     int    dd_fd;
  107.     long    dd_loc;
  108.     long    dd_size;
  109.     long    dd_bbase;
  110.     long    dd_entno;
  111.     long    dd_bsize;
  112.     char    *dd_buf;
  113. } DIR;
  114.  
  115. #if defined(__STDC__)
  116.   long telldir(DIR *dirp);
  117.   long seekdir(DIR *dirp, long loc);
  118.   DIR *opendir(const char *dirname);
  119. #else
  120.   long telldir();
  121.   void seekdir();
  122.   DIR *opendir();
  123. #endif
  124.  
  125. /*
  126.  * Place conflicting definitions here.
  127.  */
  128. #if defined(__dirent_h)
  129. /*
  130.  * Came through the <dirent.h> entry point, assume POSIX/SVR3 interface.
  131.  */
  132. #if defined(_POSIX_SOURCE) || defined(_SYSV_SOURCE)
  133.  
  134. #if defined(__STDC__)
  135.   struct dirent *readdir(DIR *dirp);
  136.   int closedir(DIR *dirp);
  137. #else
  138.   struct dirent *readdir();
  139.   int closedir();
  140. #endif
  141.  
  142. #endif /* _POSIX_SOURCE || _SYSV_SOURCE */
  143.  
  144. #if defined(_POSIX_SOURCE)
  145. #if defined(__STDC__)
  146.   void rewinddir(DIR *dirp);
  147. #else
  148.   void rewinddir();
  149. #endif
  150. #endif /* _POSIX_SOURCE */
  151.  
  152. #else /* !__dirent_h */
  153.  
  154. /*
  155.  * Else use the BSD interface (the original implementation).
  156.  */
  157. #if defined(_BSD_SOURCE)
  158. #define d_ino d_fileno        /* compatablity */
  159. #if !defined(KERNEL)
  160.  
  161. #if defined(__STDC__)
  162.   void closedir(DIR *dirp);
  163.   struct direct *readdir(DIR *dirp);
  164. #else
  165.   void closedir();
  166.   struct direct *readdir();
  167. #endif
  168.  
  169. #endif /* !KERNEL */
  170. #endif /* _BSD_SOURCE */
  171. #endif /* __dirent_h */
  172.  
  173. #if defined(_BSD_SOURCE) || defined (_SYSV_SOURCE)
  174. #if !defined(KERNEL)
  175. #define rewinddir(dirp) seekdir((dirp), (long)0)
  176. #endif /* !KERNEL */
  177. #endif
  178.  
  179. #endif /* __sys_dir_h */
  180.