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