Blob


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