lib: Move x_fgets_slash to xfile.c
[martins/samba.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 #include <stdarg.h>
24 #include <stddef.h>
25 #include <sys/stat.h>
26 #include "attr.h"
27
28 /*
29   see xfile.c for explanations
30 */
31
32 typedef struct _XFILE {
33         int fd;
34         char *buf;
35         char *next;
36         int bufsize;
37         int bufused;
38         int open_flags;
39         int buftype;
40         int flags;
41 } XFILE;
42
43 extern XFILE *x_stdin, *x_stdout, *x_stderr;
44
45 /* buffering type */
46 #define X_IOFBF 0
47 #define X_IOLBF 1
48 #define X_IONBF 2
49
50 #define x_getc(f) x_fgetc(f)
51
52 int x_vfprintf(XFILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2, 0);
53 int x_fprintf(XFILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
54
55 /** simulate setvbuf() */
56 int x_setvbuf(XFILE *f, char *buf, int mode, size_t size);
57
58 /** this looks more like open() than fopen(), but that is quite deliberate.
59    I want programmers to *think* about O_EXCL, O_CREAT etc not just
60    get them magically added 
61 */
62 XFILE *x_fopen(const char *fname, int flags, mode_t mode);
63
64 /** simulate fclose() */
65 int x_fclose(XFILE *f);
66
67 /** simulate fwrite() */
68 size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f);
69
70 /** thank goodness for asprintf() */
71 int x_fileno(const XFILE *f);
72
73 /** simulate fflush() */
74 int x_fflush(XFILE *f);
75
76 /** simulate setbuffer() */
77 void x_setbuffer(XFILE *f, char *buf, size_t size);
78
79 /** simulate setbuf() */
80 void x_setbuf(XFILE *f, char *buf);
81
82 /** simulate setlinebuf() */
83 void x_setlinebuf(XFILE *f);
84
85 /** simulate feof() */
86 int x_feof(XFILE *f);
87
88 /** simulate ferror() */
89 int x_ferror(XFILE *f);
90
91 /** simulate fgetc() */
92 int x_fgetc(XFILE *f);
93
94 /** simulate fread */
95 size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f);
96
97 /** simulate fgets() */
98 char *x_fgets(char *s, int size, XFILE *stream) ;
99
100 /** 
101  * trivial seek, works only for SEEK_SET and SEEK_END if SEEK_CUR is
102  * set then an error is returned */
103 off_t x_tseek(XFILE *f, off_t offset, int whence);
104
105 XFILE *x_fdup(const XFILE *f);
106
107 /**
108 read a line from a file with possible \ continuation chars.
109 Blanks at the start or end of a line are stripped.
110 The string will be allocated if s2 is NULL
111 **/
112 _PUBLIC_ char *x_fgets_slash(char *s2,int maxlen,XFILE *f);
113
114 #endif /* _XFILE_H_ */