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