-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathpath.3
361 lines (360 loc) · 6.89 KB
/
path.3
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LI
.aF 5 2 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX \" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS
.PD 0
.ft 5
.nf
..
.de EE \" end example
.fi
.ft
.PD
.RE
.PP
..
.TH PATH 3
.SH NAME
path \- file path routines
.SH SYNOPSIS
.EX
#include <ast.h>
char* pathaccess(char* \fIpath\fP, const char* \fIdirs\fP, const char* \fIa\fP, const char* \fIb\fP, int \fImode\fP);
char* pathbin(void);
char* pathcanon(char* \fIpath\fP, int \fIflags\fP);
char* pathcat(char* \fIpath\fP, const char* \fIdirs\fP, int \fIsep\fP, const char* \fIa\fP, const char* \fIb\fP);
char* pathcd(char* \fIpath\fP, const char* \fIhome\fP);
int pathcheck(const char* \fIpackage\fP, const char* \fItool\fP, Pathcheck_t* \fIpc\fP);
int pathgetlink(const char* \fIname\fP, char* \fIbuf\fP, int \fIsiz\fP);
int pathicase(const char* \fIpath\fP);
char* pathnext(char* \fIpath\fP, char* \fIextra\fP, long* \fIvisits\fP);
char* pathpath(char* \fIpath\fP, const char* \fIp\fP, const char* \fIa\fP, int \fImode\fP);
char* pathrepl(char* \fIpath\fP, const char* \fImatch\fP, const char* \fIreplace\fP);
int pathsetlink(const char* \fItext\fP, char* \fIname\fP);
char* pathshell(void);
int pathstat(const char* \fIpath\fP, struct stat* \fIst\fP);
char* pathtemp(char* \fIpath\fP, const char* \fIdir\fP, const char* \fIpfx\fP);
.EE
.SH DESCRIPTION
These routines operate on file path names.
Path buffers are assumed to be of size
.LR PATH_MAX .
.L <ast.h>
always defines
.LR PATH_MAX ,
even if it's indeterminate on the local system.
Yes, this was probably a bad choice, but it was made in the 1980s.
We will probably move to a <stk.h> based implementation.
.PP
.L pathaccess
constructs a path in
.L path
to the file
.L a/b
with access
.L mode
using the
.L :
separated directories in
.IR dirs .
Both
.I a
and
.I b
may be
.LR 0 .
.L mode
is the inclusive-or of:
.TP
.L F_OK
File exists.
.TP
.L R_OK
Read permission on file.
.TP
.L W_OK
Write permission on file.
.TP
.L X_OK
Execute permission on file.
.TP
.L PATH_REGULAR
A regular file.
.TP
.L PATH_ABSOLUTE
Generated path name is rooted at
.LR / .
.I path
is returned, 0 on error.
.PP
.L pathbin
returns a pointer to the
.L :
separated list of directories to search for executable commands.
The
.L PATH
environment variable is first consulted.
If not defined then
.L confstr(_CS_PATH,...)
is used.
A valid string is always returned.
.PP
.L pathcanon
canonicalizes the path
.I path
in place.
A pointer to the trailing 0 in the canonicalized path is returned.
A canonical path has:
redundant
.L .
and
.L /
removed;
.L ..
moved to the front;
.L /..
preserved for super root hacks.
.I flags is the inclusive-or of:
.TP
.L PATH_DOTDOT
Each
.L ..
is checked for access.
.TP
.L PATH_EXISTS
Path must exist at each component.
.TP
.L PATH_PHYSICAL
Symbolic links are resolved at each component.
.PP
0 is returned on error.
If an error occurs and either of
.L PATH_DOTDOT
or
.L PATH_EXISTS
is set then
.I path
will contain the components following the failure point.
.PP
.L pathcat
concatenates the first
.I sep
separated path component in
.I dirs
with the path components
.I a
and
.I b
into
.LR path .
The path is constructed in
.I path
by separating each path component with
.IR / .
Both
.I a
and
.I b
may be
.LR 0 .
A pointer to the next
.I sep
separated component in
.I dirs
is returned,
.L 0
when there are no more components.
.L pathcat
is used by
.LR pathaccess .
.PP
.L pathcd
sets the current working directory to
.I path
via
.IR chdir (2).
If
.I path
is longer than
.L PATH_MAX
then it is split up into a sequence of relative paths and
.I chdir
is called on each of these.
For any given system, if you got to a directory, then
.L pathcd
can get you back, modulo permission and link changes.
.PP
.L pathcheck
is a stub for license libraries.
See
.IR license (3).
.PP
.L pathgetlink
returns the 0-terminated symbolic link text for
.I path
in the buffer
.I bu
of size
.IR siz .
The link text length is returned on success, \-1 on error.
Weird
.IR universe (1)
interactions with dynamic symbolic links are handled
by converting non-standard dynamic link text to
.LI .../$( UNIVERSE )/...
The
.L pathsetsymlink
function
converts in the other direction.
.PP
.L pathicase
uses an operating system-specific method, if available,
to determine if a file system uses case-insensitive file names.
The return value is
.B 1
if the file system associated with the
.I path
is case-insensitive (regardless of case preservation),
.B 0
if it is not, or
.B \-1
if an error occurred. On error,
.L errno
is set by the system-specific function that was used.
If the operating system does not have a known method
to determine file system case insensitivity for the
.IR path ,
then
.L pathicase
returns
.B \-1
with
.L errno
set to
.LR ENOSYS .
.PP
.L pathpath
constructs in
.I path
a path to
.I p
with
.IR access (2)
mode
.I mode
using the directories from
.LR pathbin() .
If \fIa != 0\fP then
.IR a ,
.IR argv [0]
(if available via
.IR optget (3)),
and the
.L _
environment variable (set by
.IR ksh (1) )
are used for related root searching.
If
.I p
also contains a
.L /
then
.I ../p
is searched for.
.PP
.L pathrepl
does an in-place replacement of the first occurrence of
.I /match/
with
.I /replace/
in
.IR path .
.PP
.L pathsetlink
creates a symbolic link
.I text
in the path
.IR name .
See
.L pathgetlink
above for weird
.IR universe (1)
interactions hidden by this routine.
.PP
.L pathshell
returns a pointer to the pathname for the shell for the current process.
The
.L SHELL
environment variable is first consulted, but is rejected under suspicious
ownership/setuid conditions of if it seems to point to
.IR csh (1) ;
otherwise
.L confstr(_CS_SHELL,...)
is used.
A valid string is always returned.
.PP
.L pathstat
first tries
.LI stat( path , st )
and if that fails it tries
.LI lstat( path , st ) .
The
.L stat
or
.L lstat
return value is returned.
.PP
.L pathtemp
generates in
.I path
a temporary file path name of the form
.I dir/pfx<pid>.<suf>
where the length of
.IR pfx ,
if !=0, is limited to 5, the length of
.I <pid>
(the base 64 representation of the current process ID)
is limited to 3, and
.I <suf>
(an internally generated suffix that avoid file conflicts)
is limited to 3.
The generated path name conforms to the classic UNIX 14 char and the DOS
.LR 8.3
limitations.
Both
.I dir
and
.I pfx
may be
.LR 0 .
.IR access (2)
is used to avoid file conflicts but the generated path name is not created,
so you could lose in a race.
.SH "SEE ALSO"
access(2), confstr(3), lstat(2), stat(2)