blob: e0709b2e9394fa943dd60f70a689e430ce3ed7e6 [file] [log] [blame]
rsca5f9ff62005-01-23 22:41:44 +00001.TH SEARCHPATH 3
2.SH NAME
3search \- search for named executable
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.B
10char* searchpath(char *name)
11.SH DESCRIPTION
12.I Searchpath
13searches for the executable
14.I name
15in the same way that
16.IR sh (1)
17and
18.IR rc (1)
19do.
20.PP
21The environment variable
22.B $PATH
23is treated as a colon-separated list of directories in which to look for
24.IR name .
25An empty string in the list is treated as the current directory.
26If an executable named
27.I name
28is found in one of the directories,
29.I searchpath
30returns a pointer to a malloced string containing a path
31.IB \fR( dir / name \fR,
32or simply
33.IR name )
34suitable for use in
35.IR open (3)
36or
37.IR exec (3).
38.PP
39If
40.I name
41begins with
42.B ./ ,
43.B ../ ,
44or
45.B / ,
46then the search path is ignored.
47If
48.I name
49exists and is an executable, then
50.I searchpath
51returns a malloced string containing name.
52.PP
53The returned buffer should be freed when no longer needed.
54If
55.I name
56is not found,
57.I searchpath
58returns nil.
59.PP
60.SH SOURCE
61.B \*9/src/lib9/searchpath.c