aboutsummaryrefslogtreecommitdiff
path: root/man/man3/dirread.3
blob: cce8d97856ea3d1bbe86d4462fd0ca7631042e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
.TH DIRREAD 3
.SH NAME
dirread, dirreadall \- read directory
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.PP
.B
long dirread(int fd, Dir **buf)
.PP
.B
long dirreadall(int fd, Dir **buf)
.PP
.B
#define	STATMAX	65535U
.PP
.B
#define	DIRMAX	(sizeof(Dir)+STATMAX)
.SH DESCRIPTION
The data returned by a
.MR read (3)
on a directory is a set of complete directory entries
in a machine-independent format, exactly equivalent to
the result of a
.MR stat (3)
on each file or subdirectory in the directory.
.I Dirread
decodes the directory entries into a machine-dependent form.
It reads from
.IR fd
and unpacks the data into an array of
.B Dir
structures
whose address is returned in
.B *buf
(see
.MR stat (3)
for the layout of a
.BR Dir ).
The array is allocated with
.MR malloc (3)
each time
.I dirread
is called.
.PP
.I Dirreadall
is like
.IR dirread ,
but reads in the entire directory; by contrast,
.I dirread
steps through a directory one
.MR read (3)
at a time.
.PP
Directory entries have variable length.
A successful
.I read
of a directory always returns an integral number of complete directory entries;
.I dirread
always returns complete
.B Dir
structures.
See
.IR read (9p)
for more information.
.PP
The constant
.B STATMAX
is the maximum size that a directory entry can occupy.
The constant
.B DIRMAX
is an upper limit on the size necessary to hold a
.B Dir
structure and all the associated data.
.PP
.I Dirread
and
.I dirreadall
return the number of
.B Dir
structures filled in
.BR buf .
The file offset is advanced by the number of bytes actually read.
.SH SOURCE
.B \*9/src/lib9/dirread.c
.SH SEE ALSO
.MR intro (3) ,
.MR open (3) ,
.MR read (3)
.SH DIAGNOSTICS
.I Dirread
and
.I Dirreadall
return zero for end of file and a negative value for error.
In either case,
.B *buf
is set to
.B nil
so the pointer can always be freed with impunity.
.PP
These functions set
.IR errstr .