summaryrefslogtreecommitdiff
path: root/bgetding.c
blob: cc427e25ba4ed34f876f3c9b76901bb095190452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <u.h>
#include <libc.h>
#include <bio.h>

typedef struct
{
	double x, y, z;
} Vec;

void
usage(void)
{
	fprint(2, "usage: %s [file]\n", argv0);
	exits("usage");
}

void
main(int argc, char *argv[])
{
	Biobuf *bin;
	Vec v;
	int fd, r;

	fd = 0;
	ARGBEGIN{
	default: usage();
	}ARGEND;
	if(argc > 1)
		usage();
	else if(argc == 1){
		fd = open(argv[0], OREAD);
		if(fd < 0)
			sysfatal("open: %r");
	}
	bin = Bfdopen(fd, OREAD);
	if(bin == nil)
		sysfatal("Bfdopen: %r");
	r = Bgetd(bin, &v.x);
	print("got %g r=%d\n", v.x, r);
	r = Bgetd(bin, &v.y);
	print("got %g r=%d\n", v.y, r);
	r = Bgetd(bin, &v.z);
	print("got %g r=%d\n", v.z, r);
	Bterm(bin);
	exits(0);
}