1 /*
2 ** fdbuf.c - Buffering functions for file descriptors
3 **
4 ** Copyright (c) 1997-2000 Peter Eriksson <pen@lysator.liu.se>
5 **
6 ** This program is free software; you can redistribute it and/or
7 ** modify it as you wish - as long as you don't claim that you wrote
8 ** it.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 */
14 
15 #ifndef PLIB_FDBUF_H
16 #define PLIB_FDBUF_H
17 
18 #include "plib/threads.h"
19 
20 #define FDBUF_INBUFSIZE 8192
21 #define FDBUF_OUTBUFSIZE 8192
22 
23 #define FDF_CRLF  	0x0001
24 #define FDF_LINEBUF	0x0002
25 #define FDF_TELNET	0x0004
26 
27 
28 typedef struct
29 {
30     pthread_mutex_t refcnt_lock;
31     int refcnt;
32 
33     int flags;
34     int fd;
35 
36     pthread_mutex_t in_lock;
37     int ungetc;
38     int in_start;
39     int in_end;
40     int inbufsize;
41     unsigned char *inbuf;
42 
43     pthread_mutex_t out_lock;
44     int lastc;
45     int outbuflen;
46     int outbufsize;
47     unsigned char *outbuf;
48 } FDBUF;
49 
50 
51 
52 extern FDBUF *
53 fd_create(int fd,
54 	  int flags);
55 
56 extern void
57 fd_destroy(FDBUF *fdp);
58 
59 extern int
60 fd_fill(FDBUF *fdp);
61 
62 extern int
63 fd_flush(FDBUF *fdp);
64 
65 extern int
66 fd_putc(FDBUF *fdp,
67 	int c);
68 
69 extern int
70 fd_puts(FDBUF *fdp,
71 	const char *str);
72 
73 extern int
74 fd_printf(FDBUF *fdp,
75 	  const char *fmt,
76 	  ...);
77 
78 extern int
79 fd_getc(FDBUF *fdp);
80 
81 extern int
82 fd_gets(FDBUF *fdp,
83 	char *buf,
84 	int bufsize);
85 
86 #endif
87