blob: 7c5ba4edd203695fda78523b22027f784ec99dc9 (
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
104
105
106
107
108
109
110
111
112
113
114
|
<head>
<title>dirread(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>DIRREAD(3)</b><td align=right><b>DIRREAD(3)</b>
<tr><td width=20><td colspan=2>
<br>
<p><font size=+1><b>NAME </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
dirread, dirreadall – read directory<br>
</table>
<p><font size=+1><b>SYNOPSIS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>#include <u.h><br>
#include <libc.h>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>long dirread(int fd, Dir **buf)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>long dirreadall(int fd, Dir **buf)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>#define STATMAX 65535U
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>#define DIRMAX (sizeof(Dir)+STATMAX)<br>
</font></tt>
</table>
<p><font size=+1><b>DESCRIPTION </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
The data returned by a <a href="../man3/read.html"><i>read</i>(3)</a> on a directory is a set of complete
directory entries in a machine-independent format, exactly equivalent
to the result of a <a href="../man3/stat.html"><i>stat</i>(3)</a> on each file or subdirectory in the
directory. <i>Dirread</i> decodes the directory entries into a machine-dependent
form. It reads from <i>fd</i> and unpacks the data
into an array of <tt><font size=+1>Dir</font></tt> structures whose address is returned in <tt><font size=+1>*buf</font></tt>
(see <a href="../man3/stat.html"><i>stat</i>(3)</a> for the layout of a <tt><font size=+1>Dir</font></tt>). The array is allocated
with <a href="../man3/malloc.html"><i>malloc</i>(3)</a> each time <i>dirread</i> is called.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Dirreadall</i> is like <i>dirread</i>, but reads in the entire directory;
by contrast, <i>dirread</i> steps through a directory one <a href="../man3/read.html"><i>read</i>(3)</a> at
a time.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Directory entries have variable length. A successful <i>read</i> of a
directory always returns an integral number of complete directory
entries; <i>dirread</i> always returns complete <tt><font size=+1>Dir</font></tt> structures. See <i>read</i>(9p)
for more information.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
The constant <tt><font size=+1>STATMAX</font></tt> is the maximum size that a directory entry
can occupy. The constant <tt><font size=+1>DIRMAX</font></tt> is an upper limit on the size
necessary to hold a <tt><font size=+1>Dir</font></tt> structure and all the associated data.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<i>Dirread</i> and <i>dirreadall</i> return the number of <tt><font size=+1>Dir</font></tt> structures filled
in <tt><font size=+1>buf</font></tt>. The file offset is advanced by the number of bytes actually
read.<br>
</table>
<p><font size=+1><b>SOURCE </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>/usr/local/plan9/src/lib9/dirread.c<br>
</font></tt>
</table>
<p><font size=+1><b>SEE ALSO </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<a href="../man3/intro.html"><i>intro</i>(3)</a>, <a href="../man3/open.html"><i>open</i>(3)</a>, <a href="../man3/read.html"><i>read</i>(3)</a><br>
</table>
<p><font size=+1><b>DIAGNOSTICS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<i>Dirread</i> and <i>Dirreadall</i> return zero for end of file and a negative
value for error. In either case, <tt><font size=+1>*buf</font></tt> is set to <tt><font size=+1>nil</font></tt> so the pointer
can always be freed with impunity.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
These functions set <i>errstr</i>.<br>
</table>
<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>
|