bio.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Biobuf Biobuf;
  10. typedef struct Biobuf Biobufhdr;
  11. enum
  12. {
  13. Bsize = 8*1024,
  14. Bungetsize = UTFmax+1, /* space for ungetc */
  15. Bmagic = 0x314159,
  16. Beof = -1,
  17. Bbad = -2,
  18. Binactive = 0, /* states */
  19. Bractive,
  20. Bwactive,
  21. Bracteof,
  22. };
  23. struct Biobuf
  24. {
  25. int icount; /* neg num of bytes at eob */
  26. int ocount; /* num of bytes at bob */
  27. int rdline; /* num of bytes after rdline */
  28. int runesize; /* num of bytes of last getrune */
  29. int state; /* r/w/inactive */
  30. int fid; /* open file */
  31. int flag; /* magic if malloc'ed */
  32. int64_t offset; /* offset of buffer in file */
  33. int bsize; /* size of buffer */
  34. uint8_t* bbuf; /* pointer to beginning of buffer */
  35. uint8_t* ebuf; /* pointer to end of buffer */
  36. uint8_t* gbuf; /* pointer to good data in buf */
  37. uint8_t b[Bungetsize+Bsize];
  38. };
  39. /* Dregs, redefined as functions for backwards compatibility */
  40. #define BGETC(bp) Bgetc(bp)
  41. #define BPUTC(bp,c) Bputc(bp,c)
  42. #define BOFFSET(bp) Boffset(bp)
  43. #define BLINELEN(bp) Blinelen(bp)
  44. #define BFILDES(bp) Bfildes(bp)
  45. int Bbuffered(Biobufhdr*);
  46. int Bfildes(Biobufhdr*);
  47. int Bflush(Biobufhdr*);
  48. int Bgetc(Biobufhdr*);
  49. int Bgetd(Biobufhdr*, double*);
  50. int32_t Bgetrune(Biobufhdr*);
  51. int Binit(Biobuf*, int, int);
  52. int Binits(Biobufhdr*, int, int, uint8_t*, int);
  53. int Blinelen(Biobufhdr*);
  54. int64_t Boffset(Biobufhdr*);
  55. Biobuf* Bopen(char*, int);
  56. int Bprint(Biobufhdr*, char*, ...);
  57. int Bvprint(Biobufhdr*, char*, va_list);
  58. int Bputc(Biobufhdr*, int);
  59. int Bputrune(Biobufhdr*, int32_t);
  60. void* Brdline(Biobufhdr*, int);
  61. char* Brdstr(Biobufhdr*, int, int);
  62. int32_t Bread(Biobufhdr*, void*, int32_t);
  63. int64_t Bseek(Biobufhdr*, int64_t, int);
  64. int Bterm(Biobufhdr*);
  65. int Bungetc(Biobufhdr*);
  66. int Bungetrune(Biobufhdr*);
  67. int32_t Bwrite(Biobufhdr*, void*, int32_t);