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
RevLine 
[3eddaff]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
[777832e]3 * Copyright (c) 2018 Jiri Svoboda
[3eddaff]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
[fadd381]30/** @addtogroup libc
[b2951e2]31 * @{
32 */
33/** @file
34 */
35
[4805495]36#ifndef _LIBC_STDIO_H_
37#define _LIBC_STDIO_H_
[3eddaff]38
[3214a20]39#include <stdarg.h>
[aa492fe]40#include <io/verify.h>
[4e6a610]41#include <_bits/NULL.h>
[1d6dd2a]42#include <_bits/size_t.h>
43#include <_bits/wchar_t.h>
[ed88c8e]44#include <_bits/wint_t.h>
[bc56f30]45#include <_bits/decls.h>
[c23275a]46
[4e6a610]47#ifndef _HELENOS_SOURCE
48#define _IONBF 0
49#define _IOLBF 1
50#define _IOFBF 2
[c23275a]51#endif
52
[ef8bcc6]53/** Default size for stream I/O buffers */
[db24058]54#define BUFSIZ 4096
[ef8bcc6]55
[4e6a610]56#define EOF (-1)
57
[777832e]58/** Max number of files that is guaranteed to be able to open at the same time */
[bc56f30]59#define FOPEN_MAX 16
[777832e]60
[55092672]61/** Recommended size of fixed-size array for holding file names. */
62#define FILENAME_MAX 4096
63
[4e6a610]64/** Length of "/tmp/tmp.XXXXXX" + 1 */
65#define L_tmpnam 16
[04b687b]66
[4e6a610]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
[777832e]81
[bc56f30]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
[2595dab]93extern FILE *stdin;
94extern FILE *stdout;
95extern FILE *stderr;
96
97/* Character and string input functions */
98extern int fgetc(FILE *);
[c62d2e1]99extern char *fgets(char *, int, FILE *);
[296890f3]100extern char *gets(char *, size_t) __attribute__((deprecated));
[1c1002a]101
[bc56f30]102static inline int getc(FILE *f)
103{
104 return fgetc(f);
105}
106
[b27a97bb]107extern int getchar(void);
108
[2595dab]109/* Character and string output functions */
[ed88c8e]110extern int fputc(int, FILE *);
[2595dab]111extern int fputs(const char *, FILE *);
112
[bc56f30]113static inline int putc(int i, FILE *f)
114{
115 return fputc(i, f);
116}
117
[ed88c8e]118extern int putchar(int);
[ab00d5a]119extern int puts(const char *);
[3eddaff]120
[bd5414e]121extern int ungetc(int, FILE *);
122
[ed88c8e]123extern wint_t fputwc(wchar_t, FILE *);
124extern wint_t putwchar(wchar_t);
125
[2595dab]126/* Formatted string output functions */
[1433ecda]127extern int fprintf(FILE *, const char *, ...)
[09d13c8e]128 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
[2595dab]129extern int vfprintf(FILE *, const char *, va_list);
[3214a20]130
[9ac2013]131extern int printf(const char *, ...)
[09d13c8e]132 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
[ab00d5a]133extern int vprintf(const char *, va_list);
[3214a20]134
[1433ecda]135extern int snprintf(char *, size_t, const char *, ...)
[09d13c8e]136 _HELENOS_PRINTF_ATTRIBUTE(3, 4);
[55092672]137#if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
[a9763c6]138extern int vasprintf(char **, const char *, va_list);
[9ac2013]139extern int asprintf(char **, const char *, ...)
[09d13c8e]140 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
[296890f3]141#endif
[2595dab]142extern int vsnprintf(char *, size_t, const char *, va_list);
[a8e9ab8d]143
[296890f3]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
[5a6c28d1]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);
[ed18e14]155
[2595dab]156/* File stream functions */
[04b687b]157extern FILE *fopen(const char *, const char *);
[80bee81]158extern FILE *freopen(const char *, const char *, FILE *);
[04b687b]159extern int fclose(FILE *);
[2595dab]160
[04b687b]161extern size_t fread(void *, size_t, size_t, FILE *);
162extern size_t fwrite(const void *, size_t, size_t, FILE *);
[2595dab]163
[777832e]164extern int fgetpos(FILE *, fpos_t *);
165extern int fsetpos(FILE *, const fpos_t *);
166
[456c086]167extern int fseek(FILE *, long, int);
[080ad7f]168extern void rewind(FILE *);
[456c086]169extern long ftell(FILE *);
[04b687b]170extern int feof(FILE *);
[2595dab]171
172extern int fflush(FILE *);
[04b687b]173extern int ferror(FILE *);
174extern void clearerr(FILE *);
175
[777832e]176extern void perror(const char *);
177
[58daded]178extern int setvbuf(FILE *, void *, int, size_t);
[7699c21]179extern void setbuf(FILE *, void *);
[ef8bcc6]180
[b942a66]181/* Misc file functions */
182extern int remove(const char *);
[4e6a610]183extern int rename(const char *, const char *);
[b942a66]184
[4e6a610]185extern FILE *tmpfile(void);
[b79903b]186extern char *tmpnam(char *s);
[bc1b297]187
[bc56f30]188__C_DECLS_END;
189
[bc1b297]190#ifdef _HELENOS_SOURCE
191
[bc56f30]192#include <_bits/off64_t.h>
193
194__HELENOS_DECLS_BEGIN;
195
[bc1b297]196/* Nonstandard extensions. */
197
[bc56f30]198enum __buffer_type {
[bc1b297]199 /** No buffering */
200 _IONBF,
201 /** Line buffering */
202 _IOLBF,
203 /** Full buffering */
204 _IOFBF
205};
206
[cca2d93b]207extern int vprintf_length(const char *, va_list);
208extern int printf_length(const char *, ...)
[bc1b297]209 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
210extern FILE *fdopen(int, const char *);
211extern int fileno(FILE *);
212
[1c7f381]213extern int fseek64(FILE *, off64_t, int);
214extern off64_t ftell64(FILE *);
215
[bc56f30]216__HELENOS_DECLS_END;
[82fd245]217#endif
218
[3eddaff]219#endif
[b2951e2]220
[fadd381]221/** @}
[b2951e2]222 */
Note: See TracBrowser for help on using the repository browser.