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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e3480d5 was e3480d5, checked in by Maurizio Lombardi <m.lombardi85@…>, 12 years ago

add lseek() to the posix library, move SEEK_CUR, SEEK_SET and SEEK_END from stdio.h to unistd.h

  • Property mode set to 100644
File size: 7.0 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
68typedef struct _IO_FILE FILE;
69
70#ifndef LIBPOSIX_INTERNAL
71 enum _buffer_type {
72 /** No buffering */
73 _IONBF,
74 /** Line buffering */
75 _IOLBF,
76 /** Full buffering */
77 _IOFBF
78 };
79#endif
80
81extern FILE *stdin;
82extern FILE *stdout;
83extern FILE *stderr;
84
85extern int fgetc(FILE *);
86extern char *fgets(char *, int, FILE *);
87
88extern int getchar(void);
89extern char *gets(char *, size_t);
90
91extern int fputc(wchar_t, FILE *);
92extern int fputs(const char *, FILE *);
93
94extern int putchar(wchar_t);
95extern int puts(const char *);
96
97extern int fprintf(FILE *, const char*, ...) PRINTF_ATTRIBUTE(2, 3);
98extern int vfprintf(FILE *, const char *, va_list);
99
100extern int printf(const char *, ...) PRINTF_ATTRIBUTE(1, 2);
101extern int vprintf(const char *, va_list);
102
103extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
104#ifdef _GNU_SOURCE
105extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
106#endif
107extern int vsnprintf(char *, size_t, const char *, va_list);
108
109extern FILE *fopen(const char *, const char *);
110extern FILE *fdopen(int, const char *);
111extern int fclose(FILE *);
112
113extern size_t fread(void *, size_t, size_t, FILE *);
114extern size_t fwrite(const void *, size_t, size_t, FILE *);
115
116extern void rewind(FILE *);
117extern int feof(FILE *);
118extern int fileno(FILE *);
119
120extern int fflush(FILE *);
121extern int ferror(FILE *);
122extern void clearerr(FILE *);
123
124extern void setvbuf(FILE *, void *, int, size_t);
125
126
127/* POSIX specific stuff. */
128
129/* Identifying the Terminal */
130#undef L_ctermid
131#define L_ctermid PATH_MAX
132extern char *__POSIX_DEF__(ctermid)(char *s);
133
134/* Error Recovery */
135extern void __POSIX_DEF__(clearerr)(FILE *stream);
136
137/* Input/Output */
138#undef putc
139#define putc fputc
140extern int __POSIX_DEF__(fputs)(const char *restrict s, FILE *restrict stream);
141#undef getc
142#define getc fgetc
143extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);
144extern ssize_t __POSIX_DEF__(getdelim)(char **restrict lineptr, size_t *restrict n,
145 int delimiter, FILE *restrict stream);
146extern ssize_t __POSIX_DEF__(getline)(char **restrict lineptr, size_t *restrict n,
147 FILE *restrict stream);
148
149/* Opening Streams */
150extern FILE *__POSIX_DEF__(freopen)(const char *restrict filename,
151 const char *restrict mode, FILE *restrict stream);
152
153/* Error Messages */
154extern void __POSIX_DEF__(perror)(const char *s);
155
156/* File Positioning */
157typedef struct _posix_fpos __POSIX_DEF__(fpos_t);
158extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t) *pos);
159extern int __POSIX_DEF__(fgetpos)(FILE *restrict stream, __POSIX_DEF__(fpos_t) *restrict pos);
160extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);
161extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
162extern long __POSIX_DEF__(ftell)(FILE *stream);
163extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);
164
165/* Flushing Buffers */
166extern int __POSIX_DEF__(fflush)(FILE *stream);
167
168/* Formatted Output */
169extern int __POSIX_DEF__(dprintf)(int fildes, const char *restrict format, ...)
170 PRINTF_ATTRIBUTE(2, 3);
171extern int __POSIX_DEF__(vdprintf)(int fildes, const char *restrict format, va_list ap);
172extern int __POSIX_DEF__(sprintf)(char *restrict s, const char *restrict format, ...)
173 PRINTF_ATTRIBUTE(2, 3);
174extern int __POSIX_DEF__(vsprintf)(char *restrict s, const char *restrict format, va_list ap);
175
176/* Formatted Input */
177extern int __POSIX_DEF__(fscanf)(
178 FILE *restrict stream, const char *restrict format, ...);
179extern int __POSIX_DEF__(vfscanf)(
180 FILE *restrict stream, const char *restrict format, va_list arg);
181extern int __POSIX_DEF__(scanf)(const char *restrict format, ...);
182extern int __POSIX_DEF__(vscanf)(const char *restrict format, va_list arg);
183extern int __POSIX_DEF__(sscanf)(
184 const char *restrict s, const char *restrict format, ...);
185extern int __POSIX_DEF__(vsscanf)(
186 const char *restrict s, const char *restrict format, va_list arg);
187
188/* File Locking */
189extern void __POSIX_DEF__(flockfile)(FILE *file);
190extern int __POSIX_DEF__(ftrylockfile)(FILE *file);
191extern void __POSIX_DEF__(funlockfile)(FILE *file);
192extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);
193extern int __POSIX_DEF__(getchar_unlocked)(void);
194extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);
195extern int __POSIX_DEF__(putchar_unlocked)(int c);
196
197/* Deleting Files */
198extern int __POSIX_DEF__(remove)(const char *path);
199
200/* Renaming Files */
201extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);
202
203/* Temporary Files */
204#undef L_tmpnam
205#define L_tmpnam PATH_MAX
206extern char *__POSIX_DEF__(tmpnam)(char *s);
207extern char *__POSIX_DEF__(tempnam)(const char *dir, const char *pfx);
208extern FILE *__POSIX_DEF__(tmpfile)(void);
209
210
211#endif /* POSIX_STDIO_H_ */
212
213/** @}
214 */
Note: See TracBrowser for help on using the repository browser.