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