1 /*
2  *  ircd-ratbox: A slightly useful ircd.
3  *  fileio.h: The file input/output header.
4  *
5  *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6  *  Copyright (C) 1996-2002 Hybrid Development Team
7  *  Copyright (C) 2002-2004 ircd-ratbox development team
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
22  *  USA
23  *
24  *  $Id: fileio.h,v 1.1 2005/02/15 19:16:09 chopin Exp $
25  */
26 
27 #ifndef INCLUDED_fileio_h
28 #define INCLUDED_fileio_h
29 
30 #define FB_EOF  0x01
31 #define FB_FAIL 0x02
32 
33 struct FileBuf
34 {
35 	int fd;			/* file descriptor */
36 	char *endp;		/* one past the end */
37 	char *ptr;		/* current read pos */
38 	char *pbptr;		/* pointer to push back char */
39 	int flags;		/* file state */
40 	char buf[BUFSIZ];	/* buffer */
41 	char pbuf[BUFSIZ + 1];	/* push back buffer */
42 };
43 
44 /* XXX This shouldn't be here */
45 struct Client;
46 
47 /*
48  * FileBuf is a mirror of the ANSI FILE struct, but it works for any
49  * file descriptor. FileBufs are allocated when a file is opened with
50  * fbopen, and they are freed when the file is closed using fbclose.
51  */
52 typedef struct FileBuf FBFILE;
53 
54 /*
55  * open a file and return a FBFILE*, see fopen(3)
56  */
57 extern FBFILE *fbopen(const char *filename, const char *mode);
58 /*
59  * associate a file descriptor with a FBFILE*
60  * if a FBFILE* is associated here it MUST be closed using fbclose
61  * see fdopen(3)
62  */
63 extern FBFILE *fdbopen(int fd, const char *mode);
64 /*
65  * close a file opened with fbopen, see fclose(3)
66  */
67 extern void fbclose(FBFILE * fb);
68 /*
69  * return the next character from the file, EOF on end of file
70  * see fgetc(3)
71  */
72 extern int fbgetc(FBFILE * fb);
73 /*
74  * return next string in a file up to and including the newline character
75  * see fgets(3)
76  */
77 extern char *fbgets(char *buf, size_t len, FBFILE * fb);
78 /*
79  * ungets c to fb see ungetc(3)
80  */
81 extern void fbungetc(char c, FBFILE * fb);
82 /*
83  * write a null terminated string to a file, see fputs(3)
84  */
85 extern int fbputs(const char *str, FBFILE * fb);
86 /*
87  * return the status of the file associated with fb, see fstat(3)
88  */
89 extern int fbstat(struct stat *sb, FBFILE * fb);
90 /*
91  * popen a file.
92  */
93 extern FBFILE *fbpopen(const char *, const char *);
94 
95 #endif /* INCLUDED_fileio_h */
96