xref: /haiku/headers/posix/stdio.h (revision 90dca2bc8ea3f248a1fe87fda98bc7f822dfcd38)
1 /*
2  * Copyright 2004-2012 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _STDIO_H_
6 #define _STDIO_H_
7 
8 
9 #include <sys/types.h>
10 #include <null.h>
11 #include <stdarg.h>
12 
13 
14 /* Dodge gcc 2.95.3's fixincludes hack stdio_va_list by including this string:
15  * __gnuc_va_list */
16 
17 
18 #define BUFSIZ			8192
19 #define _IOFBF			0		/* fully buffered */
20 #define _IOLBF			1		/* line buffered */
21 #define _IONBF			2		/* not buffered */
22 
23 /*
24  * FOPEN_MAX is a minimum maximum, and should be the number of descriptors
25  * that the kernel can provide without allocation of a resource that can
26  * fail without the process sleeping.  Do not use this for anything
27  */
28 #define FOPEN_MAX		128
29 #define STREAM_MAX		FOPEN_MAX
30 #define FILENAME_MAX	256
31 #define TMP_MAX			32768
32 
33 #define L_ctermid  		32
34 #define L_cuserid  		32
35 #define	L_tmpnam		512
36 
37 #define	P_tmpdir		"/tmp/"
38 
39 #ifdef EOF
40 #	undef EOF
41 #endif
42 #define EOF (-1)
43 
44 #ifndef SEEK_SET
45 #	define SEEK_SET 0
46 #endif
47 #ifndef SEEK_CUR
48 #	define SEEK_CUR 1
49 #endif
50 #ifndef SEEK_END
51 #	define SEEK_END 2
52 #endif
53 
54 
55 typedef off_t fpos_t;
56 
57 #include <stdio_pre.h>
58 
59 extern FILE *stdin;
60 extern FILE *stdout;
61 extern FILE *stderr;
62 
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 /* file operations */
69 extern FILE		*fopen(const char *name, const char *mode);
70 extern FILE		*freopen(const char *name, const char *mode, FILE *stream);
71 extern FILE		*fdopen(int fd, const char *mode);
72 extern int		fclose(FILE *stream);
73 #ifdef _DEFAULT_SOURCE
74 extern int		fcloseall(void);
75 #endif
76 
77 extern int		fileno(FILE *stream);
78 extern int		fileno_unlocked(FILE *stream);
79 
80 extern int		ferror(FILE *stream);
81 extern int		ferror_unlocked(FILE *stream);
82 extern void		clearerr(FILE *stream);
83 extern void		clearerr_unlocked(FILE *stream);
84 
85 extern int		feof(FILE *stream);
86 extern int		feof_unlocked(FILE *stream);
87 
88 extern void		flockfile(FILE *stream);
89 extern void		funlockfile(FILE *stream);
90 extern int		ftrylockfile(FILE *stream);
91 
92 extern int		remove(const char *name);
93 extern int		rename(const char *from, const char *to);
94 extern int		renameat(int fromFD, const char *from, int toFD, const char *to);
95 
96 /* pipes */
97 extern FILE		*popen(const char *command, const char *mode);
98 extern int		pclose(FILE *stream);
99 extern void		perror(const char *errorPrefix);
100 
101 /* memory streams */
102 extern FILE		*fmemopen(void *buf, size_t size, const char *mode);
103 extern FILE		*open_memstream(char **buf, size_t *size);
104 
105 /* callback streams */
106 #ifdef _DEFAULT_SOURCE
107 typedef ssize_t (*cookie_read_function_t)(void *cookie, char *buf, size_t size);
108 typedef ssize_t (*cookie_write_function_t)(void *cookie, const char *buf, size_t size);
109 typedef ssize_t (*cookie_seek_function_t)(void *cookie, off_t *offset, int whence);
110 typedef ssize_t (*cookie_close_function_t)(void *cookie);
111 typedef struct {
112 	cookie_read_function_t  *read;
113 	cookie_write_function_t *write;
114 	cookie_seek_function_t  *seek;
115 	cookie_close_function_t *close;
116 } cookie_io_functions_t;
117 extern FILE		*fopencookie(void *cookie, const char *mode, cookie_io_functions_t io_funcs);
118 #endif /* _DEFAULT_SOURCE */
119 
120 /* file I/O */
121 extern int		fflush(FILE *stream);
122 extern int		fflush_unlocked(FILE *stream);
123 extern int		fpurge(FILE *stream);
124 
125 extern int		fgetpos(FILE *stream, fpos_t *position);
126 extern int		fsetpos(FILE *stream, const fpos_t *position);
127 extern int		fseek(FILE *stream, long offset, int seekType);
128 extern int		fseeko(FILE *stream, off_t offset, int seekType);
129 extern int		_fseek(FILE *stream, fpos_t offset, int seekType);
130 extern long		ftell(FILE *stream);
131 extern off_t	ftello(FILE *stream);
132 extern fpos_t	_ftell(FILE *stream);
133 
134 extern void		rewind(FILE *stream);
135 
136 extern void		setbuf (FILE *file, char *buff);
137 extern int		setvbuf(FILE *file, char *buff, int mode, size_t size);
138 extern int		setbuffer(FILE *stream, char *buf, size_t size);
139 extern int 	    	setlinebuf(FILE *stream);
140 
141 extern size_t	fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream);
142 extern size_t	fwrite_unlocked(const void *buffer, size_t size, size_t numItems, FILE *stream);
143 extern size_t	fread(void *buffer, size_t size, size_t numItems, FILE *stream);
144 extern size_t	fread_unlocked(void *buffer, size_t size, size_t numItems, FILE *stream);
145 
146 extern int		putc(int c, FILE *stream);
147 extern int		putchar(int c);
148 extern int		putc_unlocked(int c, FILE *stream);
149 extern int		putchar_unlocked(int c);
150 extern int		fputc(int c, FILE *stream);
151 extern int		fputc_unlocked(int c, FILE *stream);
152 extern int		puts(const char *string);
153 extern int		fputs(const char *string, FILE *stream);
154 extern int		fputs_unlocked(const char *string, FILE *stream);
155 
156 extern int		getc(FILE *stream);
157 extern int		getc_unlocked(FILE *stream);
158 extern int		ungetc(int c, FILE *stream);
159 extern int		getchar(void);
160 extern int		getchar_unlocked(void);
161 extern int		fgetc(FILE *stream);
162 extern int		fgetc_unlocked(FILE *stream);
163 extern char		*gets(char *buffer);
164 extern char		*fgets(char *string, int stringLength, FILE *stream);
165 extern char		*fgets_unlocked(char *string, int stringLength, FILE *stream);
166 
167 extern ssize_t	getdelim(char **_line, size_t *_length, int delimiter,
168 					FILE *stream);
169 extern ssize_t	getline(char **_line, size_t *_length, FILE *stream);
170 
171 /* formatted I/O */
172 extern int		printf(char const *format, ...) __PRINTFLIKE(1,2);
173 #if !defined(_KERNEL_MODE) && !defined(_BOOT_MODE) && !defined(_LOADER_MODE)
174 extern int		dprintf(int fd, char const *format, ...) __PRINTFLIKE(2,3);
175 #endif
176 extern int		fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3);
177 extern int		sprintf(char *string, char const *format, ...) __PRINTFLIKE(2,3);
178 extern int		snprintf(char *string, size_t size, char const *format, ...) __PRINTFLIKE(3,4);
179 extern int		vprintf(char const *format, va_list ap);
180 extern int		vfprintf(FILE *stream, char const *format, va_list ap);
181 extern int		vsprintf(char *string, char const *format, va_list ap);
182 extern int		vsnprintf(char *string, size_t size, char const *format, va_list ap);
183 
184 extern int		scanf(char const *format, ...);
185 extern int		fscanf(FILE *stream, char const *format, ...);
186 extern int		sscanf(char const *str, char const *format, ...);
187 extern int		vscanf(char const *format, va_list ap);
188 extern int		vsscanf(char const *str, char const *format, va_list ap);
189 extern int		vfscanf(FILE *stream, char const *format, va_list ap);
190 
191 /* misc */
192 extern char		*ctermid(char *controllingTerminal);
193 extern char		*cuserid(char *s);
194 
195 /* temporary files */
196 extern char		*tempnam(char const *path, char const *prefix);
197 extern FILE		*tmpfile(void);
198 extern char 	*tmpnam(char *nameBuffer);
199 extern char 	*tmpnam_r(char *nameBuffer);
200 
201 #include <stdio_post.h>
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 
208 #endif	/* _STDIO_H_ */
209