1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#ifndef SUBSTDIO_H
#define SUBSTDIO_H
#include <sys/types.h>
typedef ssize_t (*substdio_op)(int, const void *, size_t);
typedef struct substdio {
char *x;
int p;
int n;
int fd;
substdio_op op;
} substdio;
#define SUBSTDIO_FDBUF(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
extern void substdio_fdbuf(substdio *s, substdio_op, int, char *, int);
extern int substdio_flush(substdio *);
extern int substdio_put(substdio *, char *, int);
extern int substdio_bput(substdio *, char *, int);
extern int substdio_putflush(substdio *, char *, int);
extern int substdio_puts(substdio *, char *);
extern int substdio_bputs(substdio *, char *);
extern int substdio_putsflush(substdio *, char *);
extern int substdio_get(substdio *, char *, int);
extern int substdio_bget(substdio *, char *, int);
extern int substdio_feed(substdio *);
extern char *substdio_peek(substdio *);
extern void substdio_seek(substdio *, int);
#define substdio_fileno(s) ((s)->fd)
#define SUBSTDIO_INSIZE 8192
#define SUBSTDIO_OUTSIZE 8192
#define substdio_PEEK(s) ( (s)->x + (s)->n )
#define substdio_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
#define substdio_BPUTC(s,c) \
( ((s)->n != (s)->p) \
? ( (s)->x[(s)->p++] = (c), 0 ) \
: substdio_bput((s),&(c),1) \
)
extern int substdio_copy(substdio *, substdio *);
#endif
|