Merge branch 'selftest' of git://git.samba.org/jelmer/samba
[ira/wip.git] / lib / util / xfile.h
1 /* 
2    Unix SMB/CIFS implementation.
3    stdio replacement
4    Copyright (C) Andrew Tridgell 2001
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _XFILE_H_
21 #define _XFILE_H_
22 /*
23   see xfile.c for explanations
24 */
25
26 typedef struct {
27         int fd;
28         char *buf;
29         char *next;
30         int bufsize;
31         int bufused;
32         int open_flags;
33         int buftype;
34         int flags;
35 } XFILE;
36
37 extern XFILE *x_stdin, *x_stdout, *x_stderr;
38
39 /* buffering type */
40 #define X_IOFBF 0
41 #define X_IOLBF 1
42 #define X_IONBF 2
43
44 #define x_getc(f) x_fgetc(f)
45
46 int x_vfprintf(XFILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2, 0);
47 int x_fprintf(XFILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
48
49 /** simulate setvbuf() */
50 int x_setvbuf(XFILE *f, char *buf, int mode, size_t size);
51
52 /** this looks more like open() than fopen(), but that is quite deliberate.
53    I want programmers to *think* about O_EXCL, O_CREAT etc not just
54    get them magically added 
55 */
56 XFILE *x_fopen(const char *fname, int flags, mode_t mode);
57
58 /** simulate fclose() */
59 int x_fclose(XFILE *f);
60
61 /** simulate fwrite() */
62 size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f);
63
64 /** thank goodness for asprintf() */
65 int x_fileno(const XFILE *f);
66
67 /** simulate fflush() */
68 int x_fflush(XFILE *f);
69
70 /** simulate setbuffer() */
71 void x_setbuffer(XFILE *f, char *buf, size_t size);
72
73 /** simulate setbuf() */
74 void x_setbuf(XFILE *f, char *buf);
75
76 /** simulate setlinebuf() */
77 void x_setlinebuf(XFILE *f);
78
79 /** simulate feof() */
80 int x_feof(XFILE *f);
81
82 /** simulate ferror() */
83 int x_ferror(XFILE *f);
84
85 /** simulate fgetc() */
86 int x_fgetc(XFILE *f);
87
88 /** simulate fread */
89 size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f);
90
91 /** simulate fgets() */
92 char *x_fgets(char *s, int size, XFILE *stream) ;
93
94 /** 
95  * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is
96  * set then an error is returned */
97 off_t x_tseek(XFILE *f, off_t offset, int whence);
98
99 XFILE *x_fdup(const XFILE *f);
100
101 #endif /* _XFILE_H_ */