bio.h 2.3 KB

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