1
0

bio.h 1.8 KB

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