bio.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Biobuf 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 Biobuf
  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. uint8_t b[Bungetsize+Bsize];
  40. };
  41. /* Dregs, redefined as functions for backwards compatibility */
  42. #define BGETC(bp) Bgetc(bp)
  43. #define BPUTC(bp,c) Bputc(bp,c)
  44. #define BOFFSET(bp) Boffset(bp)
  45. #define BLINELEN(bp) Blinelen(bp)
  46. #define BFILDES(bp) Bfildes(bp)
  47. int Bbuffered(Biobufhdr*);
  48. int Bfildes(Biobufhdr*);
  49. int Bflush(Biobufhdr*);
  50. int Bgetc(Biobufhdr*);
  51. int Bgetd(Biobufhdr*, double*);
  52. int32_t Bgetrune(Biobufhdr*);
  53. int Binit(Biobuf*, int, int);
  54. int Binits(Biobufhdr*, int, int, uint8_t*, int);
  55. int Blinelen(Biobufhdr*);
  56. int64_t Boffset(Biobufhdr*);
  57. Biobuf* Bopen(char*, int);
  58. int Bprint(Biobufhdr*, char*, ...);
  59. int Bvprint(Biobufhdr*, char*, va_list);
  60. int Bputc(Biobufhdr*, int);
  61. int Bputrune(Biobufhdr*, int32_t);
  62. void* Brdline(Biobufhdr*, int);
  63. char* Brdstr(Biobufhdr*, int, int);
  64. int32_t Bread(Biobufhdr*, void*, int32_t);
  65. int64_t Bseek(Biobufhdr*, int64_t, int);
  66. int Bterm(Biobufhdr*);
  67. int Bungetc(Biobufhdr*);
  68. int Bungetrune(Biobufhdr*);
  69. int32_t Bwrite(Biobufhdr*, void*, int32_t);
  70. #pragma varargck argpos Bprint 2