wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

bio.h (2123B)


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