source: mainline/uspace/lib/c/include/stdio.h@ 92a7cfb1

Last change on this file since 92a7cfb1 was bc56f30, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Make some libc and libposix headers usable in C++

These headers either get included from standard C++ headers,
or are standard themselves, which means any unnamespaced nonstandard
identifiers are a problem. This commit attempts to fix those
issues, and removes hacks previously used in libcpp to work around it.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * Copyright (c) 2018 Jiri Svoboda
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 libc
31 * @{
32 */
33/** @file
34 */
35
36#ifndef _LIBC_STDIO_H_
37#define _LIBC_STDIO_H_
38
39#include <stdarg.h>
40#include <io/verify.h>
41#include <_bits/NULL.h>
42#include <_bits/size_t.h>
43#include <_bits/wchar_t.h>
44#include <_bits/wint_t.h>
45#include <_bits/decls.h>
46
47#ifndef _HELENOS_SOURCE
48#define _IONBF 0
49#define _IOLBF 1
50#define _IOFBF 2
51#endif
52
53/** Default size for stream I/O buffers */
54#define BUFSIZ 4096
55
56#define EOF (-1)
57
58/** Max number of files that is guaranteed to be able to open at the same time */
59#define FOPEN_MAX 16
60
61/** Recommended size of fixed-size array for holding file names. */
62#define FILENAME_MAX 4096
63
64/** Length of "/tmp/tmp.XXXXXX" + 1 */
65#define L_tmpnam 16
66
67#ifndef SEEK_SET
68#define SEEK_SET 0
69#endif
70
71#ifndef SEEK_CUR
72#define SEEK_CUR 1
73#endif
74
75#ifndef SEEK_END
76#define SEEK_END 2
77#endif
78
79/** Minimum number of unique temporary file names */
80#define TMP_MAX 1000000
81
82__C_DECLS_BEGIN;
83
84/** Forward declaration */
85struct _IO_FILE;
86typedef struct _IO_FILE FILE;
87
88/** File position */
89typedef struct {
90 long long pos;
91} fpos_t;
92
93extern FILE *stdin;
94extern FILE *stdout;
95extern FILE *stderr;
96
97/* Character and string input functions */
98extern int fgetc(FILE *);
99extern char *fgets(char *, int, FILE *);
100extern char *gets(char *, size_t) __attribute__((deprecated));
101
102static inline int getc(FILE *f)
103{
104 return fgetc(f);
105}
106
107extern int getchar(void);
108
109/* Character and string output functions */
110extern int fputc(int, FILE *);
111extern int fputs(const char *, FILE *);
112
113static inline int putc(int i, FILE *f)
114{
115 return fputc(i, f);
116}
117
118extern int putchar(int);
119extern int puts(const char *);
120
121extern int ungetc(int, FILE *);
122
123extern wint_t fputwc(wchar_t, FILE *);
124extern wint_t putwchar(wchar_t);
125
126/* Formatted string output functions */
127extern int fprintf(FILE *, const char *, ...)
128 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
129extern int vfprintf(FILE *, const char *, va_list);
130
131extern int printf(const char *, ...)
132 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
133extern int vprintf(const char *, va_list);
134
135extern int snprintf(char *, size_t, const char *, ...)
136 _HELENOS_PRINTF_ATTRIBUTE(3, 4);
137#if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
138extern int vasprintf(char **, const char *, va_list);
139extern int asprintf(char **, const char *, ...)
140 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
141#endif
142extern int vsnprintf(char *, size_t, const char *, va_list);
143
144extern int sprintf(char *, const char *, ...)
145 __attribute__((deprecated)) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
146extern int vsprintf(char *, const char *, va_list) __attribute__((deprecated));
147
148/* Formatted input */
149extern int scanf(const char *, ...);
150extern int vscanf(const char *, va_list);
151extern int fscanf(FILE *, const char *, ...);
152extern int vfscanf(FILE *, const char *, va_list);
153extern int sscanf(const char *, const char *, ...);
154extern int vsscanf(const char *, const char *, va_list);
155
156/* File stream functions */
157extern FILE *fopen(const char *, const char *);
158extern FILE *freopen(const char *, const char *, FILE *);
159extern int fclose(FILE *);
160
161extern size_t fread(void *, size_t, size_t, FILE *);
162extern size_t fwrite(const void *, size_t, size_t, FILE *);
163
164extern int fgetpos(FILE *, fpos_t *);
165extern int fsetpos(FILE *, const fpos_t *);
166
167extern int fseek(FILE *, long, int);
168extern void rewind(FILE *);
169extern long ftell(FILE *);
170extern int feof(FILE *);
171
172extern int fflush(FILE *);
173extern int ferror(FILE *);
174extern void clearerr(FILE *);
175
176extern void perror(const char *);
177
178extern int setvbuf(FILE *, void *, int, size_t);
179extern void setbuf(FILE *, void *);
180
181/* Misc file functions */
182extern int remove(const char *);
183extern int rename(const char *, const char *);
184
185extern FILE *tmpfile(void);
186extern char *tmpnam(char *s);
187
188__C_DECLS_END;
189
190#ifdef _HELENOS_SOURCE
191
192#include <_bits/off64_t.h>
193
194__HELENOS_DECLS_BEGIN;
195
196/* Nonstandard extensions. */
197
198enum __buffer_type {
199 /** No buffering */
200 _IONBF,
201 /** Line buffering */
202 _IOLBF,
203 /** Full buffering */
204 _IOFBF
205};
206
207extern int vprintf_length(const char *, va_list);
208extern int printf_length(const char *, ...)
209 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
210extern FILE *fdopen(int, const char *);
211extern int fileno(FILE *);
212
213extern int fseek64(FILE *, off64_t, int);
214extern off64_t ftell64(FILE *);
215
216__HELENOS_DECLS_END;
217#endif
218
219#endif
220
221/** @}
222 */
Note: See TracBrowser for help on using the repository browser.