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