Blame


1 f7012583 2003-11-25 devnull #ifndef _BIO_H_
2 f7012583 2003-11-25 devnull #define _BIO_H_ 1
3 f7012583 2003-11-25 devnull #if defined(__cplusplus)
4 f7012583 2003-11-25 devnull extern "C" {
5 f7012583 2003-11-25 devnull #endif
6 b2cfc4e2 2003-09-30 devnull
7 78e51a8c 2005-01-14 devnull #ifdef AUTOLIB
8 1a0954ab 2005-01-04 devnull AUTOLIB(bio)
9 78e51a8c 2005-01-14 devnull #endif
10 1a0954ab 2005-01-04 devnull
11 b2cfc4e2 2003-09-30 devnull #include <fcntl.h> /* for O_RDONLY, O_WRONLY */
12 b2cfc4e2 2003-09-30 devnull
13 b2cfc4e2 2003-09-30 devnull typedef struct Biobuf Biobuf;
14 b2cfc4e2 2003-09-30 devnull
15 b2cfc4e2 2003-09-30 devnull enum
16 b2cfc4e2 2003-09-30 devnull {
17 b2cfc4e2 2003-09-30 devnull Bsize = 8*1024,
18 b2cfc4e2 2003-09-30 devnull Bungetsize = 4, /* space for ungetc */
19 b2cfc4e2 2003-09-30 devnull Bmagic = 0x314159,
20 b2cfc4e2 2003-09-30 devnull Beof = -1,
21 b2cfc4e2 2003-09-30 devnull Bbad = -2,
22 b2cfc4e2 2003-09-30 devnull
23 b2cfc4e2 2003-09-30 devnull Binactive = 0, /* states */
24 b2cfc4e2 2003-09-30 devnull Bractive,
25 b2cfc4e2 2003-09-30 devnull Bwactive,
26 b2cfc4e2 2003-09-30 devnull Bracteof,
27 b2cfc4e2 2003-09-30 devnull
28 b2cfc4e2 2003-09-30 devnull Bend
29 b2cfc4e2 2003-09-30 devnull };
30 b2cfc4e2 2003-09-30 devnull
31 b2cfc4e2 2003-09-30 devnull struct Biobuf
32 b2cfc4e2 2003-09-30 devnull {
33 b2cfc4e2 2003-09-30 devnull int icount; /* neg num of bytes at eob */
34 b2cfc4e2 2003-09-30 devnull int ocount; /* num of bytes at bob */
35 b2cfc4e2 2003-09-30 devnull int rdline; /* num of bytes after rdline */
36 669250d1 2003-12-03 devnull int runesize; /* num of bytes of last getrune */
37 b2cfc4e2 2003-09-30 devnull int state; /* r/w/inactive */
38 b2cfc4e2 2003-09-30 devnull int fid; /* open file */
39 b2cfc4e2 2003-09-30 devnull int flag; /* magic if malloc'ed */
40 f533d4e0 2008-06-03 rsc long long offset; /* offset of buffer in file */
41 b2cfc4e2 2003-09-30 devnull int bsize; /* size of buffer */
42 b2cfc4e2 2003-09-30 devnull unsigned char* bbuf; /* pointer to beginning of buffer */
43 b2cfc4e2 2003-09-30 devnull unsigned char* ebuf; /* pointer to end of buffer */
44 b2cfc4e2 2003-09-30 devnull unsigned char* gbuf; /* pointer to good data in buf */
45 b2cfc4e2 2003-09-30 devnull unsigned char b[Bungetsize+Bsize];
46 b2cfc4e2 2003-09-30 devnull };
47 b2cfc4e2 2003-09-30 devnull
48 b2cfc4e2 2003-09-30 devnull #define BGETC(bp)\
49 b2cfc4e2 2003-09-30 devnull ((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp)))
50 b2cfc4e2 2003-09-30 devnull #define BPUTC(bp,c)\
51 b2cfc4e2 2003-09-30 devnull ((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c)))
52 b2cfc4e2 2003-09-30 devnull #define BOFFSET(bp)\
53 b2cfc4e2 2003-09-30 devnull (((bp)->state==Bractive)?\
54 b2cfc4e2 2003-09-30 devnull (bp)->offset + (bp)->icount:\
55 b2cfc4e2 2003-09-30 devnull (((bp)->state==Bwactive)?\
56 b2cfc4e2 2003-09-30 devnull (bp)->offset + ((bp)->bsize + (bp)->ocount):\
57 b2cfc4e2 2003-09-30 devnull -1))
58 b2cfc4e2 2003-09-30 devnull #define BLINELEN(bp)\
59 b2cfc4e2 2003-09-30 devnull (bp)->rdline
60 b2cfc4e2 2003-09-30 devnull #define BFILDES(bp)\
61 b2cfc4e2 2003-09-30 devnull (bp)->fid
62 b2cfc4e2 2003-09-30 devnull
63 b2cfc4e2 2003-09-30 devnull int Bbuffered(Biobuf*);
64 986b36bc 2003-11-23 devnull Biobuf* Bfdopen(int, int);
65 b2cfc4e2 2003-09-30 devnull int Bfildes(Biobuf*);
66 b2cfc4e2 2003-09-30 devnull int Bflush(Biobuf*);
67 b2cfc4e2 2003-09-30 devnull int Bgetc(Biobuf*);
68 b2cfc4e2 2003-09-30 devnull int Bgetd(Biobuf*, double*);
69 623ae4f9 2004-12-28 devnull long Bgetrune(Biobuf*);
70 b2cfc4e2 2003-09-30 devnull int Binit(Biobuf*, int, int);
71 b2cfc4e2 2003-09-30 devnull int Binits(Biobuf*, int, int, unsigned char*, int);
72 b2cfc4e2 2003-09-30 devnull int Blinelen(Biobuf*);
73 f533d4e0 2008-06-03 rsc long long Boffset(Biobuf*);
74 b2cfc4e2 2003-09-30 devnull Biobuf* Bopen(char*, int);
75 b2cfc4e2 2003-09-30 devnull int Bprint(Biobuf*, char*, ...);
76 b2cfc4e2 2003-09-30 devnull int Bputc(Biobuf*, int);
77 623ae4f9 2004-12-28 devnull int Bputrune(Biobuf*, long);
78 b2cfc4e2 2003-09-30 devnull void* Brdline(Biobuf*, int);
79 623ae4f9 2004-12-28 devnull char* Brdstr(Biobuf*, int, int);
80 b2cfc4e2 2003-09-30 devnull long Bread(Biobuf*, void*, long);
81 f533d4e0 2008-06-03 rsc long long Bseek(Biobuf*, long long, int);
82 b2cfc4e2 2003-09-30 devnull int Bterm(Biobuf*);
83 b2cfc4e2 2003-09-30 devnull int Bungetc(Biobuf*);
84 522b0689 2003-09-30 devnull int Bungetrune(Biobuf*);
85 b2cfc4e2 2003-09-30 devnull long Bwrite(Biobuf*, void*, long);
86 623ae4f9 2004-12-28 devnull int Bvprint(Biobuf*, char*, va_list);
87 b2cfc4e2 2003-09-30 devnull
88 f7012583 2003-11-25 devnull #if defined(__cplusplus)
89 f7012583 2003-11-25 devnull }
90 b2cfc4e2 2003-09-30 devnull #endif
91 f7012583 2003-11-25 devnull #endif