blob: 9c9ed26071fed53dafa31d39dd24f8e726c94c28 [file] [log] [blame]
rsc058b0112005-01-03 06:40:20 +00001.TH GET9ROOT 3
2.SH NAME
3get9root, unsharp \- get path to root of Plan 9 tree
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.B
10char* get9root(void)
11.PP
12.B
13char* unsharp(char *path)
14.SH DESCRIPTION
15This tree of Plan 9 software is conventionally installed in
rscc3674de2005-01-11 17:37:33 +000016.B \*9
rsc058b0112005-01-03 06:40:20 +000017but may be installed in other places (for example, users without
18the ability to write to
19.B /usr/local
20may with to install it in their own home directories).
21The environment variable
22.B $PLAN9
23should contain the path to the root.
24.I Get9root
25returns a static pointer to the pathname of root, first checking
26.B $PLAN9
27and defaulting to
rscc3674de2005-01-11 17:37:33 +000028.BR \*9 .
rsc058b0112005-01-03 06:40:20 +000029.PP
30The lack of a fixed location for the Plan 9 tree
31makes it difficult to hard-code paths
32to files.
33.I Unsharp
34replaces a leading
35.B #9
36in
37.I path
38with the root of the tree.
39.I Unsharp
40also replaces a leading
41.B #d
42with the path to the underlying system's file descriptor dup device,
43typically
44.BR /dev/fd .
45The string returned from
46.IR unsharp ,
47if different from
48.IR path ,
49should be freed with
50.I free
51(see
52.IR malloc (3))
53when no longer needed.
54.PP
55As a convention, programs should never
56.I unsharp
57paths obtained from user input.
58.SH EXAMPLE
59The
60.IR plumber (4)
61uses this code to find unrooted file names included by plumb rules.
62.IP
63.EX
64snprint(buf, sizeof buf, "#9/plumb/%s", name);
65fd = open(unsharp(buf), OREAD);
66.EE
67.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000068.B \*9/src/lib9/getns.c
rsc058b0112005-01-03 06:40:20 +000069.SH SEE ALSO
70.IR intro (4)
71.SH BUGS
72.I Get9root
73could be smarter about finding the tree when
74.B $PLAN9
75is not set.