diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/ap/plan9/9iounit.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/9iounit.c')
-rwxr-xr-x | sys/src/ape/lib/ap/plan9/9iounit.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/plan9/9iounit.c b/sys/src/ape/lib/ap/plan9/9iounit.c new file mode 100755 index 000000000..7117a9fe0 --- /dev/null +++ b/sys/src/ape/lib/ap/plan9/9iounit.c @@ -0,0 +1,65 @@ +#include "lib.h" +#include <string.h> +#include <stdlib.h> +#include <fmt.h> +#include "sys9.h" +#include "dir.h" + +/* + * Format: + 3 r M 4 (0000000000457def 11 00) 8192 512 /rc/lib/rcmain + */ + +static int +getfields(char *str, char **args, int max, int mflag) +{ + char r; + int nr, intok, narg; + + if(max <= 0) + return 0; + + narg = 0; + args[narg] = str; + if(!mflag) + narg++; + intok = 0; + for(;;) { + r = *str++; + if(r == 0) + break; + if(r == ' ' || r == '\t'){ + if(narg >= max) + break; + *str = 0; + intok = 0; + args[narg] = str + nr; + if(!mflag) + narg++; + } else { + if(!intok && mflag) + narg++; + intok = 1; + } + } + return narg; +} +int +_IOUNIT(int fd) +{ + int i, cfd; + char buf[128], *args[10]; + + snprint(buf, sizeof buf, "#d/%dctl", fd); + cfd = _OPEN(buf, OREAD); + if(cfd < 0) + return 0; + i = _READ(cfd, buf, sizeof buf-1); + _CLOSE(cfd); + if(i <= 0) + return 0; + buf[i] = '\0'; + if(getfields(buf, args, 10, 1) != 10) + return 0; + return atoi(args[7]); +} |