bio.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma src "/usr/inferno/libbio"
  2. typedef struct Biobuf Biobuf;
  3. enum
  4. {
  5. Bsize = 8*1024,
  6. Bungetsize = UTFmax+1, /* space for ungetc */
  7. Bmagic = 0x314159,
  8. Beof = -1,
  9. Bbad = -2,
  10. Binactive = 0, /* states */
  11. Bractive,
  12. Bwactive,
  13. Bracteof,
  14. Bend
  15. };
  16. struct Biobuf
  17. {
  18. int icount; /* neg num of bytes at eob */
  19. int ocount; /* num of bytes at bob */
  20. int rdline; /* num of bytes after rdline */
  21. int runesize; /* num of bytes of last getrune */
  22. int state; /* r/w/inactive */
  23. int fid; /* open file */
  24. int flag; /* magic if malloc'ed */
  25. vlong offset; /* offset of buffer in file */
  26. int bsize; /* size of buffer */
  27. uchar* bbuf; /* pointer to beginning of buffer */
  28. uchar* ebuf; /* pointer to end of buffer */
  29. uchar* gbuf; /* pointer to good data in buf */
  30. uchar b[Bungetsize+Bsize];
  31. };
  32. /* Dregs, redefined as functions for backwards compatibility */
  33. #define BGETC(bp) Bgetc(bp)
  34. #define BPUTC(bp,c) Bputc(bp,c)
  35. #define BOFFSET(bp) Boffset(bp)
  36. #define BLINELEN(bp) Blinelen(bp)
  37. #define BFILDES(bp) Bfildes(bp)
  38. int Bbuffered(Biobuf*);
  39. int Bfildes(Biobuf*);
  40. int Bflush(Biobuf*);
  41. int Bgetc(Biobuf*);
  42. int Bgetd(Biobuf*, double*);
  43. long Bgetrune(Biobuf*);
  44. int Binit(Biobuf*, int, int);
  45. int Binits(Biobuf*, int, int, uchar*, int);
  46. int Blinelen(Biobuf*);
  47. vlong Boffset(Biobuf*);
  48. Biobuf* Bopen(char*, int);
  49. int Bprint(Biobuf*, char*, ...);
  50. int Bvprint(Biobuf*, char*, va_list);
  51. int Bputc(Biobuf*, int);
  52. int Bputrune(Biobuf*, long);
  53. void* Brdline(Biobuf*, int);
  54. char* Brdstr(Biobuf*, int, int);
  55. long Bread(Biobuf*, void*, long);
  56. vlong Bseek(Biobuf*, vlong, int);
  57. int Bterm(Biobuf*);
  58. int Bungetc(Biobuf*);
  59. int Bungetrune(Biobuf*);
  60. long Bwrite(Biobuf*, void*, long);
  61. #pragma varargck argpos Bprint 2