xref: /haiku/headers/posix/stdio.h (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Copyright 2004-2010 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(void **buf, size_t *size);
101 
102 /* file I/O */
103 extern int		fflush(FILE *stream);
104 extern int		fflush_unlocked(FILE *stream);
105 extern int		fpurge(FILE *stream);
106 
107 extern int		fgetpos(FILE *stream, fpos_t *position);
108 extern int		fsetpos(FILE *stream, const fpos_t *position);
109 extern int		fseek(FILE *stream, long offset, int seekType);
110 extern int		fseeko(FILE *stream, off_t offset, int seekType);
111 extern int		_fseek(FILE *stream, fpos_t offset, int seekType);
112 extern long		ftell(FILE *stream);
113 extern off_t	ftello(FILE *stream);
114 extern fpos_t	_ftell(FILE *stream);
115 
116 extern void		rewind(FILE *stream);
117 
118 extern void		setbuf (FILE *file, char *buff);
119 extern int		setvbuf(FILE *file, char *buff, int mode, size_t size);
120 extern int		setbuffer(FILE *stream, char *buf, size_t size);
121 extern int 	    	setlinebuf(FILE *stream);
122 
123 extern size_t	fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream);
124 extern size_t	fread(void *buffer, size_t size, size_t numItems, FILE *stream);
125 
126 extern int		putc(int c, FILE *stream);
127 extern int		putchar(int c);
128 extern int		putc_unlocked(int c, FILE *stream);
129 extern int		putchar_unlocked(int c);
130 extern int		fputc(int c, FILE *stream);
131 extern int		fputc_unlocked(int c, FILE *stream);
132 extern int		puts(const char *string);
133 extern int		fputs(const char *string, FILE *stream);
134 
135 extern int		getc(FILE *stream);
136 extern int		getc_unlocked(FILE *stream);
137 extern int		ungetc(int c, FILE *stream);
138 extern int		getchar(void);
139 extern int		getchar_unlocked(void);
140 extern int		fgetc(FILE *stream);
141 extern char		*gets(char *buffer);
142 extern char		*fgets(char *string, int stringLength, FILE *stream);
143 
144 extern ssize_t	getdelim(char **_line, size_t *_length, int delimiter,
145 					FILE *stream);
146 extern ssize_t	getline(char **_line, size_t *_length, FILE *stream);
147 
148 /* formatted I/O */
149 extern int		printf(char const *format, ...) __PRINTFLIKE(1,2);
150 extern int		fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3);
151 extern int		sprintf(char *string, char const *format, ...) __PRINTFLIKE(2,3);
152 extern int		snprintf(char *string, size_t size, char const *format, ...) __PRINTFLIKE(3,4);
153 extern int		asprintf(char **ret, char const *format, ...) __PRINTFLIKE(2,3);
154 extern int		vprintf(char const *format, va_list ap);
155 extern int		vfprintf(FILE *stream, char const *format, va_list ap);
156 extern int		vsprintf(char *string, char const *format, va_list ap);
157 extern int		vsnprintf(char *string, size_t size, char const *format, va_list ap);
158 extern int		vasprintf(char **ret, char const *format, va_list ap);
159 
160 extern int		scanf(char const *format, ...);
161 extern int		fscanf(FILE *stream, char const *format, ...);
162 extern int		sscanf(char const *str, char const *format, ...);
163 extern int		vscanf(char const *format, va_list ap);
164 extern int		vsscanf(char const *str, char const *format, va_list ap);
165 extern int		vfscanf(FILE *stream, char const *format, va_list ap);
166 
167 /* misc */
168 extern char		*ctermid(char *controllingTerminal);
169 extern char		*cuserid(char *s);
170 
171 /* temporary files */
172 extern char		*tempnam(char const *path, char const *prefix);
173 extern FILE		*tmpfile(void);
174 extern char 	*tmpnam(char *nameBuffer);
175 extern char 	*tmpnam_r(char *nameBuffer);
176 
177 #include <stdio_post.h>
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 
184 #endif	/* _STDIO_H_ */
185