source: mainline/uspace/lib/posix/include/posix/stdio.h@ 06b0211b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 06b0211b was 06b0211b, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Merge mainline changes

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Standard buffered input/output.
34 */
35
36#ifndef POSIX_STDIO_H_
37#define POSIX_STDIO_H_
38
39#ifndef __POSIX_DEF__
40#define __POSIX_DEF__(x) x
41/* DEBUG macro does not belong to POSIX stdio.h. Its unconditional
42 * definition in the native stdio.h causes unexpected behaviour of
43 * applications which uses their own DEBUG macro (e.g. debugging
44 * output is printed even if not desirable). */
45#undef DEBUG
46#endif
47
48#include "stddef.h"
49#include "unistd.h"
50#include "libc/io/verify.h"
51#include "sys/types.h"
52#include "stdarg.h"
53#include "limits.h"
54
55/*
56 * These are the same as in HelenOS libc.
57 * It would be possible to directly include <stdio.h> but
58 * it is better not to pollute POSIX namespace with other functions
59 * defined in that header.
60 *
61 * Because libposix is always linked with libc, providing only these
62 * forward declarations ought to be enough.
63 */
64#define EOF (-1)
65
66#define BUFSIZ 4096
67#define SEEK_SET 0
68#define SEEK_CUR 1
69#define SEEK_END 2
70
71typedef struct _IO_FILE FILE;
72
73#ifndef LIBPOSIX_INTERNAL
74 enum _buffer_type {
75 /** No buffering */
76 _IONBF,
77 /** Line buffering */
78 _IOLBF,
79 /** Full buffering */
80 _IOFBF
81 };
82#endif
83
84extern FILE *stdin;
85extern FILE *stdout;
86extern FILE *stderr;
87
88extern int fgetc(FILE *);
89extern char *fgets(char *, int, FILE *);
90
91extern int getchar(void);
92extern char *gets(char *, size_t);
93
94extern int fputc(wchar_t, FILE *);
95extern int fputs(const char *, FILE *);
96
97extern int putchar(wchar_t);
98extern int puts(const char *);
99
100extern int fprintf(FILE *, const char*, ...) PRINTF_ATTRIBUTE(2, 3);
101extern int vfprintf(FILE *, const char *, va_list);
102
103extern int printf(const char *, ...) PRINTF_ATTRIBUTE(1, 2);
104extern int vprintf(const char *, va_list);
105
106extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
107#ifdef _GNU_SOURCE
108extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
109#endif
110extern int vsnprintf(char *, size_t, const char *, va_list);
111
112extern FILE *fopen(const char *, const char *);
113extern FILE *fdopen(int, const char *);
114extern int fclose(FILE *);
115
116extern size_t fread(void *, size_t, size_t, FILE *);
117extern size_t fwrite(const void *, size_t, size_t, FILE *);
118
119extern void rewind(FILE *);
120extern int feof(FILE *);
121extern int fileno(FILE *);
122
123extern int fflush(FILE *);
124extern int ferror(FILE *);
125extern void clearerr(FILE *);
126
127extern void setvbuf(FILE *, void *, int, size_t);
128
129
130/* POSIX specific stuff. */
131
132/* Identifying the Terminal */
133#undef L_ctermid
134#define L_ctermid PATH_MAX
135extern char *__POSIX_DEF__(ctermid)(char *s);
136
137/* Error Recovery */
138extern void __POSIX_DEF__(clearerr)(FILE *stream);
139
140/* Input/Output */
141#undef putc
142#define putc fputc
143extern int __POSIX_DEF__(fputs)(const char *restrict s, FILE *restrict stream);
144#undef getc
145#define getc fgetc
146extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);
147extern ssize_t __POSIX_DEF__(getdelim)(char **restrict lineptr, size_t *restrict n,
148 int delimiter, FILE *restrict stream);
149extern ssize_t __POSIX_DEF__(getline)(char **restrict lineptr, size_t *restrict n,
150 FILE *restrict stream);
151
152/* Opening Streams */
153extern FILE *__POSIX_DEF__(freopen)(const char *restrict filename,
154 const char *restrict mode, FILE *restrict stream);
155
156/* Error Messages */
157extern void __POSIX_DEF__(perror)(const char *s);
158
159/* File Positioning */
160typedef struct _posix_fpos __POSIX_DEF__(fpos_t);
161extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t) *pos);
162extern int __POSIX_DEF__(fgetpos)(FILE *restrict stream, __POSIX_DEF__(fpos_t) *restrict pos);
163extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);
164extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
165extern long __POSIX_DEF__(ftell)(FILE *stream);
166extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);
167
168/* Flushing Buffers */
169extern int __POSIX_DEF__(fflush)(FILE *stream);
170
171/* Formatted Output */
172extern int __POSIX_DEF__(dprintf)(int fildes, const char *restrict format, ...)
173 PRINTF_ATTRIBUTE(2, 3);
174extern int __POSIX_DEF__(vdprintf)(int fildes, const char *restrict format, va_list ap);
175extern int __POSIX_DEF__(sprintf)(char *restrict s, const char *restrict format, ...)
176 PRINTF_ATTRIBUTE(2, 3);
177extern int __POSIX_DEF__(vsprintf)(char *restrict s, const char *restrict format, va_list ap);
178
179/* Formatted Input */
180extern int __POSIX_DEF__(fscanf)(
181 FILE *restrict stream, const char *restrict format, ...);
182extern int __POSIX_DEF__(vfscanf)(
183 FILE *restrict stream, const char *restrict format, va_list arg);
184extern int __POSIX_DEF__(scanf)(const char *restrict format, ...);
185extern int __POSIX_DEF__(vscanf)(const char *restrict format, va_list arg);
186extern int __POSIX_DEF__(sscanf)(
187 const char *restrict s, const char *restrict format, ...);
188extern int __POSIX_DEF__(vsscanf)(
189 const char *restrict s, const char *restrict format, va_list arg);
190
191/* File Locking */
192extern void __POSIX_DEF__(flockfile)(FILE *file);
193extern int __POSIX_DEF__(ftrylockfile)(FILE *file);
194extern void __POSIX_DEF__(funlockfile)(FILE *file);
195extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);
196extern int __POSIX_DEF__(getchar_unlocked)(void);
197extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);
198extern int __POSIX_DEF__(putchar_unlocked)(int c);
199
200/* Deleting Files */
201extern int __POSIX_DEF__(remove)(const char *path);
202
203/* Renaming Files */
204extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);
205
206/* Temporary Files */
207#undef L_tmpnam
208#define L_tmpnam PATH_MAX
209extern char *__POSIX_DEF__(tmpnam)(char *s);
210extern char *__POSIX_DEF__(tempnam)(const char *dir, const char *pfx);
211extern FILE *__POSIX_DEF__(tmpfile)(void);
212
213
214#endif /* POSIX_STDIO_H_ */
215
216/** @}
217 */
Note: See TracBrowser for help on using the repository browser.