Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_fixcpp/sys/src/ape/lib/ap/plan9/9iounit.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "lib.h"
2
#include <string.h>
3
#include <stdlib.h>
4
#include <fmt.h>
5
#include "sys9.h"
6
#include "dir.h"
7
 
8
/*
9
 * Format:
10
  3 r  M    4 (0000000000457def 11 00)   8192      512 /rc/lib/rcmain
11
 */
12
 
13
static int
14
getfields(char *str, char **args, int max, int mflag)
15
{
16
	char r;
17
	int nr, intok, narg;
18
 
19
	if(max <= 0)
20
		return 0;
21
 
22
	narg = 0;
23
	args[narg] = str;
24
	if(!mflag)
25
		narg++;
26
	intok = 0;
27
	for(;;) {
28
		nr = 1;			/* utf bytes in this rune */
29
		r = *str++;
30
		if(r == 0)
31
			break;
32
		if(r == ' ' || r == '\t'){
33
			if(narg >= max)
34
				break;
35
			*str = 0;
36
			intok = 0;
37
			args[narg] = str + nr;
38
			if(!mflag)
39
				narg++;
40
		} else {
41
			if(!intok && mflag)
42
				narg++;
43
			intok = 1;
44
		}
45
	}
46
	return narg;
47
}
48
int
49
_IOUNIT(int fd)
50
{
51
	int i, cfd;
52
	char buf[128], *args[10];
53
 
54
	snprint(buf, sizeof buf, "#d/%dctl", fd);
55
	cfd = _OPEN(buf, OREAD);
56
	if(cfd < 0)
57
		return 0;
58
	i = _READ(cfd, buf, sizeof buf-1);
59
	_CLOSE(cfd);
60
	if(i <= 0)
61
		return 0;
62
	buf[i] = '\0';
63
	if(getfields(buf, args, 10, 1) != 10)
64
		return 0;
65
	return atoi(args[7]);
66
}