xref: /haiku/headers/posix/stdio.h (revision 83b732c7328f1c4601e1a64ce234b93615c0ddc8)
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 
74 extern int		fileno(FILE *stream);
75 extern int		fileno_unlocked(FILE *stream);
76 
77 extern int		ferror(FILE *stream);
78 extern int		ferror_unlocked(FILE *stream);
79 extern void		clearerr(FILE *stream);
80 extern void		clearerr_unlocked(FILE *stream);
81 
82 extern int		feof(FILE *stream);
83 extern int		feof_unlocked(FILE *stream);
84 
85 extern void		flockfile(FILE *stream);
86 extern void		funlockfile(FILE *stream);
87 extern int		ftrylockfile(FILE *stream);
88 
89 extern int		remove(const char *name);
90 extern int		rename(const char *from, const char *to);
91 extern int		renameat(int fromFD, const char *from, int toFD, const char *to);
92 
93 /* pipes */
94 extern FILE		*popen(const char *command, const char *mode);
95 extern int		pclose(FILE *stream);
96 extern void		perror(const char *errorPrefix);
97 
98 /* memory streams */
99 extern FILE		*fmemopen(void *buf, size_t size, const char *mode);
100 extern FILE		*open_memstream(char **buf, size_t *size);
101 
102 /* callback streams */
103 #ifdef _GNU_SOURCE
104 typedef ssize_t (*cookie_read_function_t)(void *cookie, char *buf, size_t size);
105 typedef ssize_t (*cookie_write_function_t)(void *cookie, const char *buf, size_t size);
106 typedef ssize_t (*cookie_seek_function_t)(void *cookie, off_t *offset, int whence);
107 typedef ssize_t (*cookie_close_function_t)(void *cookie);
108 typedef struct {
109 	cookie_read_function_t  *read;
110 	cookie_write_function_t *write;
111 	cookie_seek_function_t  *seek;
112 	cookie_close_function_t *close;
113 } cookie_io_functions_t;
114 extern FILE		*fopencookie(void *cookie, const char *mode, cookie_io_functions_t io_funcs);
115 #endif /*_GNU_SOURCE*/
116 
117 /* file I/O */
118 extern int		fflush(FILE *stream);
119 extern int		fflush_unlocked(FILE *stream);
120 extern int		fpurge(FILE *stream);
121 
122 extern int		fgetpos(FILE *stream, fpos_t *position);
123 extern int		fsetpos(FILE *stream, const fpos_t *position);
124 extern int		fseek(FILE *stream, long offset, int seekType);
125 extern int		fseeko(FILE *stream, off_t offset, int seekType);
126 extern int		_fseek(FILE *stream, fpos_t offset, int seekType);
127 extern long		ftell(FILE *stream);
128 extern off_t	ftello(FILE *stream);
129 extern fpos_t	_ftell(FILE *stream);
130 
131 extern void		rewind(FILE *stream);
132 
133 extern void		setbuf (FILE *file, char *buff);
134 extern int		setvbuf(FILE *file, char *buff, int mode, size_t size);
135 extern int		setbuffer(FILE *stream, char *buf, size_t size);
136 extern int 	    	setlinebuf(FILE *stream);
137 
138 extern size_t	fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream);
139 extern size_t	fwrite_unlocked(const void *buffer, size_t size, size_t numItems, FILE *stream);
140 extern size_t	fread(void *buffer, size_t size, size_t numItems, FILE *stream);
141 extern size_t	fread_unlocked(void *buffer, size_t size, size_t numItems, FILE *stream);
142 
143 extern int		putc(int c, FILE *stream);
144 extern int		putchar(int c);
145 extern int		putc_unlocked(int c, FILE *stream);
146 extern int		putchar_unlocked(int c);
147 extern int		fputc(int c, FILE *stream);
148 extern int		fputc_unlocked(int c, FILE *stream);
149 extern int		puts(const char *string);
150 extern int		fputs(const char *string, FILE *stream);
151 extern int		fputs_unlocked(const char *string, FILE *stream);
152 
153 extern int		getc(FILE *stream);
154 extern int		getc_unlocked(FILE *stream);
155 extern int		ungetc(int c, FILE *stream);
156 extern int		getchar(void);
157 extern int		getchar_unlocked(void);
158 extern int		fgetc(FILE *stream);
159 extern int		fgetc_unlocked(FILE *stream);
160 extern char		*gets(char *buffer);
161 extern char		*fgets(char *string, int stringLength, FILE *stream);
162 extern char		*fgets_unlocked(char *string, int stringLength, FILE *stream);
163 
164 extern ssize_t	getdelim(char **_line, size_t *_length, int delimiter,
165 					FILE *stream);
166 extern ssize_t	getline(char **_line, size_t *_length, FILE *stream);
167 
168 /* formatted I/O */
169 extern int		printf(char const *format, ...) __PRINTFLIKE(1,2);
170 extern int		fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3);
171 extern int		sprintf(char *string, char const *format, ...) __PRINTFLIKE(2,3);
172 extern int		snprintf(char *string, size_t size, char const *format, ...) __PRINTFLIKE(3,4);
173 extern int		asprintf(char **ret, char const *format, ...) __PRINTFLIKE(2,3);
174 extern int		vprintf(char const *format, va_list ap);
175 extern int		vfprintf(FILE *stream, char const *format, va_list ap);
176 extern int		vsprintf(char *string, char const *format, va_list ap);
177 extern int		vsnprintf(char *string, size_t size, char const *format, va_list ap);
178 extern int		vasprintf(char **ret, char const *format, va_list ap);
179 
180 extern int		scanf(char const *format, ...);
181 extern int		fscanf(FILE *stream, char const *format, ...);
182 extern int		sscanf(char const *str, char const *format, ...);
183 extern int		vscanf(char const *format, va_list ap);
184 extern int		vsscanf(char const *str, char const *format, va_list ap);
185 extern int		vfscanf(FILE *stream, char const *format, va_list ap);
186 
187 /* misc */
188 extern char		*ctermid(char *controllingTerminal);
189 extern char		*cuserid(char *s);
190 
191 /* temporary files */
192 extern char		*tempnam(char const *path, char const *prefix);
193 extern FILE		*tmpfile(void);
194 extern char 	*tmpnam(char *nameBuffer);
195 extern char 	*tmpnam_r(char *nameBuffer);
196 
197 #include <stdio_post.h>
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 
204 #endif	/* _STDIO_H_ */
205