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