2 * @(#) dir.h 1.4 87/11/06 Public Domain.
4 * A public domain implementation of BSD directory routines for
5 * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield),
8 * Enhanced and ported to OS/2 by Kai Uwe Rommel; added scandir() prototype
9 * December 1989, February 1990
14 #define MAXPATHLEN 128
21 #define A_ARCHIVE 0x20
26 ino_t d_ino; /* a bit of a farce */
27 int d_reclen; /* more farce */
28 int d_namlen; /* length of d_name */
29 char d_name[MAXNAMLEN + 1]; /* null terminated */
30 long d_size; /* size in bytes */
31 int d_mode; /* DOS or OS/2 file attributes */
34 /* The fields d_size and d_mode are extensions by me (Kai Uwe Rommel).
35 * The find_first and find_next calls deliver this data without any extra cost.
36 * If this data is needed, these fields save a lot of extra calls to stat()
37 * (each stat() again performs a find_first call !).
45 struct _dircontents *_d_next;
48 typedef struct _dirdesc
50 int dd_id; /* uniquely identify each open directory */
51 long dd_loc; /* where we are in directory entry is this */
52 struct _dircontents *dd_contents; /* pointer to contents of dir */
53 struct _dircontents *dd_cp; /* pointer to current position */
58 extern DIR *opendir(char *);
59 extern struct direct *readdir(DIR *);
60 extern void seekdir(DIR *, long);
61 extern long telldir(DIR *);
62 extern void closedir(DIR *);
63 #define rewinddir(dirp) seekdir(dirp, 0L)
65 extern int scandir(char *, struct direct ***,
66 int (*)(struct direct *),
67 int (*)(struct direct *, struct direct *));
69 extern int getfmode(char *);
70 extern int setfmode(char *, unsigned);
74 opendir, readdir, telldir, seekdir, rewinddir, closedir -
78 #include <sys/types.h>
81 DIR *opendir(filename)
84 struct direct *readdir(dirp)
101 The opendir library routine opens the directory named by
102 filename and associates a directory stream with it. A
103 pointer is returned to identify the directory stream in sub-
104 sequent operations. The pointer NULL is returned if the
105 specified filename can not be accessed, or if insufficient
106 memory is available to open the directory file.
108 The readdir routine returns a pointer to the next directory
109 entry. It returns NULL upon reaching the end of the direc-
110 tory or on detecting an invalid seekdir operation. The
111 readdir routine uses the getdirentries system call to read
112 directories. Since the readdir routine returns NULL upon
113 reaching the end of the directory or on detecting an error,
114 an application which wishes to detect the difference must
115 set errno to 0 prior to calling readdir.
117 The telldir routine returns the current location associated
118 with the named directory stream. Values returned by telldir
119 are good only for the lifetime of the DIR pointer from which
120 they are derived. If the directory is closed and then reo-
121 pened, the telldir value may be invalidated due to
122 undetected directory compaction.
124 The seekdir routine sets the position of the next readdir
125 operation on the directory stream. Only values returned by
126 telldir should be used with seekdir.
128 The rewinddir routine resets the position of the named
129 directory stream to the beginning of the directory.
131 The closedir routine closes the named directory stream and
132 returns a value of 0 if successful. Otherwise, a value of -1
133 is returned and errno is set to indicate the error. All
134 resources associated with this directory stream are
138 The following sample code searches a directory for the entry
145 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
147 if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
161 close(2), getdirentries(2), lseek(2), open(2), read(2),