xref: /inferno-os/libbio/bgetd.c (revision 7ef44d652ae9e5e1f5b3465d73684e4a54de73c0)
1 #include "lib9.h"
2 #include <bio.h>
3 
4 struct	bgetd
5 {
6 	Biobuf*	b;
7 	int		eof;
8 };
9 
10 static int
11 Bgetdf(void *vp)
12 {
13 	int c;
14 	struct bgetd *bg = vp;
15 
16 	c = Bgetc(bg->b);
17 	if(c == Beof)
18 		bg->eof = 1;
19 	return c;
20 }
21 
22 int
23 Bgetd(Biobuf *bp, double *dp)
24 {
25 	double d;
26 	struct bgetd b;
27 
28 	b.b = bp;
29 	b.eof = 0;
30 	d = charstod(Bgetdf, &b);
31 	if(b.eof)
32 		return -1;
33 	Bungetc(bp);
34 	*dp = d;
35 	return 1;
36 }
37