]> git.lizzy.rs Git - plan9front.git/blob - sys/include/ape/bio.h
dpost prologue: update /radicalex to fix square displacement (thanks umbraticus and...
[plan9front.git] / sys / include / ape / bio.h
1 #ifndef _PLAN9_SOURCE
2   This header file is an extension to ANSI/POSIX
3 #endif
4
5 #ifndef __BIO_H_
6 #define __BIO_H_
7 #pragma src     "/sys/src/libbio"
8 #pragma lib     "/$M/lib/ape/libbio.a"
9
10 #include <u.h>
11
12 typedef struct  Biobuf  Biobuf;
13 typedef struct  Biobufhdr       Biobufhdr;
14
15 enum
16 {
17         Bsize           = 8*1024,
18         Bungetsize      = UTFmax+1,     /* space for ungetc */
19         Bmagic          = 0x314159,
20         Beof            = -1,
21         Bbad            = -2,
22
23         Binactive       = 0,            /* states */
24         Bractive,
25         Bwactive,
26         Bracteof,
27 };
28
29 struct  Biobufhdr
30 {
31         int     icount;         /* neg num of bytes at eob */
32         int     ocount;         /* num of bytes at bob */
33         int     rdline;         /* num of bytes after rdline */
34         int     runesize;       /* num of bytes of last getrune */
35         int     state;          /* r/w/inactive */
36         int     fid;            /* open file */
37         int     flag;           /* magic if malloc'ed */
38         vlong   offset;         /* offset of buffer in file */
39         int     bsize;          /* size of buffer */
40         uchar*  bbuf;           /* pointer to beginning of buffer */
41         uchar*  ebuf;           /* pointer to end of buffer */
42         uchar*  gbuf;           /* pointer to good data in buf */
43         void    (*errorf)(char *);      /* called on error if not nil */
44         int     (*iof)(Biobufhdr*, void *, long);       /* called to do i/o */
45 };
46
47 struct  Biobuf
48 {
49         Biobufhdr;
50         uchar   b[Bungetsize+Bsize];
51 };
52
53 /* Dregs, redefined as functions for backwards compatibility */
54 #define BGETC(bp)       Bgetc(bp)
55 #define BPUTC(bp,c)     Bputc(bp,c)
56 #define BOFFSET(bp)     Boffset(bp)
57 #define BLINELEN(bp)    Blinelen(bp)
58 #define BFILDES(bp)     Bfildes(bp)
59
60 int     Bbuffered(Biobufhdr*);
61 int     Bfildes(Biobufhdr*);
62 int     Bflush(Biobufhdr*);
63 int     Bgetc(Biobufhdr*);
64 int     Bgetd(Biobufhdr*, double*);
65 long    Bgetrune(Biobufhdr*);
66 int     Binit(Biobuf*, int, int);
67 int     Binits(Biobufhdr*, int, int, uchar*, int);
68 int     Blinelen(Biobufhdr*);
69 vlong   Boffset(Biobufhdr*);
70 Biobuf* Bopen(char*, int);
71 Biobuf* Bfdopen(int, int);
72 int     Bprint(Biobufhdr*, char*, ...);
73 int     Bvprint(Biobufhdr*, char*, va_list);
74 int     Bputc(Biobufhdr*, int);
75 int     Bputrune(Biobufhdr*, long);
76 void*   Brdline(Biobufhdr*, int);
77 char*   Brdstr(Biobufhdr*, int, int);
78 long    Bread(Biobufhdr*, void*, long);
79 vlong   Bseek(Biobufhdr*, vlong, int);
80 int     Bterm(Biobufhdr*);
81 int     Bungetc(Biobufhdr*);
82 int     Bungetrune(Biobufhdr*);
83 long    Bwrite(Biobufhdr*, void*, long);
84 void    Blethal(Biobufhdr*, void(*)(char*));
85 void    Berror(Biobufhdr*, char*, ...);
86 void    Biofn(Biobufhdr*, int(*)(Biobufhdr*, void*, long));
87
88 #pragma varargck        argpos  Bprint  2
89 #pragma varargck        argpos  Berror  2
90
91 #endif