BSD 4_3 release
[unix-history] / usr / src / usr.lib / sendmail / lib / libndir / directory.3s
CommitLineData
8c212ecf
EA
1..From teklabs!ogcvax!root Tue Aug 3 05:14:38 1982
2..TH DIRECTORY 3 "OGC Revision 8/02/82"
3.TH DIRECTORY 3X 8/1/82
4.UC 4.1b Compatability
5.SH NAME
6opendir, readdir, telldir, seekdir, rewinddir, closedir \- flexible length directory operations
7.SH SYNOPSIS
8.B #include <dir.h>
9.PP
10.SM
11.B DIR
12.B *opendir(filename)
13.br
14.B char *filename;
15.PP
16.SM
17.B struct direct
18.B *readdir(dirp)
19.br
20.B DIR *dirp;
21.PP
22.SM
23.B long
24.B telldir(dirp)
25.br
26.B DIR *dirp;
27.PP
28.SM
29.B seekdir(dirp, loc)
30.br
31.B DIR *dirp;
32.br
33.B long loc;
34.PP
35.SM
36.B rewinddir(dirp)
37.br
38.B DIR *dirp;
39.PP
40.SM
41.B closedir(dirp)
42.br
43.B DIR *dirp;
44.PP
45.SM
46.B cc ... -lndir
47.SH DESCRIPTION
48The purpose of this library is to simulate
49the new flexible length directory names of 4.2bsd Unix
50on top of the old directory structure of 4.1bsd.
51It allows programs to be converted immediately
52to the new directory access interface,
53so that they need only be relinked
54when 4.2bsd becomes available.
55.PP
56.I opendir
57opens the directory named by
58.I filename
59and associates a
60.I directory stream
61with it.
62.I opendir
63returns a pointer to be used to identify the
64.I directory stream
65in subsequent operations.
66The pointer
67.SM
68.B NULL
69is returned if
70.I filename
71cannot be accessed or is not a directory.
72.PP
73.I readdir
74returns a pointer to the next directory entry.
75It returns
76.B NULL
77upon reaching the end of the directory or detecting
78an invalid
79.I seekdir
80operation.
81.PP
82.I telldir
83returns the current location associated with the named
84.I directory stream.
85.PP
86.I seekdir
87sets the position of the next
88.I readdir
89operation on the
90.I directory stream.
91The new position reverts to the one associated with the
92.I directory stream
93when the
94.I telldir
95operation was performed.
96Values returned by
97.I telldir
98are good only for the lifetime of the DIR pointer from
99which they are derived.
100If the directory is closed and then reopened,
101the
102.I telldir
103value may be invalidated
104due to undetected directory compaction.
105It is safe to use a previous
106.I telldir
107value immediately after a call to
108.I opendir
109and before any calls to
110.I readdir.
111.PP
112.I rewinddir
113resets the position of the named
114.I directory stream
115to the beginning of the directory.
116.PP
117.I closedir
118causes the named
119.I directory stream
120to be closed,
121and the structure associated with the DIR pointer to be freed.
122.PP
123See /usr/include/dir.h for a description of the fields available in
124a directory entry.
125The preferred way to search the current directory for entry "name" is:
126.br
127.sp
128 len = strlen(name);
129.br
130 dirp = opendir(".");
131.br
132 for (dp = readdir(dirp); dp != NULL; dp = readdir(dir))
133.br
134 if (dp->d_namlen == len && !strcmp(dp->d_name, name)) {
135.br
136 closedir(dirp);
137.br
138 return FOUND;
139.br
140 }
141.br
142 closedir(dirp);
143.br
144 return NOT_FOUND;
145.SH LINKING
146This library is accessed by specifying "-lndir" as the
147last argument to the compile line, e.g.:
148.br
149.sp
150 cc -o prog prog.c -lndir
151.SH "SEE ALSO"
152/usr/include/dir.h,
153open(2),
154close(2),
155read(2),
156lseek(2)
157.SH AUTHOR
158Kirk McKusick.
159Report problems to mckusick@berkeley or ucbvax!mckusick.