bio.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/lib/bio"
  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. Biobuf* Bfdopen(int, int);
  63. int Bprint(Biobufhdr*, char*, ...);
  64. int Bvprint(Biobufhdr*, char*, va_list);
  65. int Bputc(Biobufhdr*, int);
  66. int Bputrune(Biobufhdr*, int32_t);
  67. void* Brdline(Biobufhdr*, int);
  68. char* Brdstr(Biobufhdr*, int, int);
  69. int32_t Bread(Biobufhdr*, void*, int32_t);
  70. int64_t Bseek(Biobufhdr*, int64_t, int);
  71. int Bterm(Biobufhdr*);
  72. int Bungetc(Biobufhdr*);
  73. int Bungetrune(Biobufhdr*);
  74. int32_t Bwrite(Biobufhdr*, void*, int32_t);
  75. #pragma varargck argpos Bprint 2