bgetd.c 401 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. struct bgetd
  5. {
  6. Biobufhdr* b;
  7. int eof;
  8. };
  9. static int
  10. Bgetdf(void *vp)
  11. {
  12. int c;
  13. struct bgetd *bg = vp;
  14. c = Bgetc(bg->b);
  15. if(c == Beof)
  16. bg->eof = 1;
  17. return c;
  18. }
  19. int
  20. Bgetd(Biobufhdr *bp, double *dp)
  21. {
  22. double d;
  23. struct bgetd b;
  24. b.b = bp;
  25. b.eof = 0;
  26. d = charstod(Bgetdf, &b);
  27. if(b.eof)
  28. return -1;
  29. Bungetc(bp);
  30. *dp = d;
  31. return 1;
  32. }