[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>
|
---|
[28a5ebd] | 44 | #include <_bits/uchar.h>
|
---|
[ed88c8e] | 45 | #include <_bits/wint_t.h>
|
---|
[bc56f30] | 46 | #include <_bits/decls.h>
|
---|
[c23275a] | 47 |
|
---|
[4e6a610] | 48 | #ifndef _HELENOS_SOURCE
|
---|
| 49 | #define _IONBF 0
|
---|
| 50 | #define _IOLBF 1
|
---|
| 51 | #define _IOFBF 2
|
---|
[c23275a] | 52 | #endif
|
---|
| 53 |
|
---|
[ef8bcc6] | 54 | /** Default size for stream I/O buffers */
|
---|
[db24058] | 55 | #define BUFSIZ 4096
|
---|
[ef8bcc6] | 56 |
|
---|
[4e6a610] | 57 | #define EOF (-1)
|
---|
| 58 |
|
---|
[777832e] | 59 | /** Max number of files that is guaranteed to be able to open at the same time */
|
---|
[bc56f30] | 60 | #define FOPEN_MAX 16
|
---|
[777832e] | 61 |
|
---|
[55092672] | 62 | /** Recommended size of fixed-size array for holding file names. */
|
---|
| 63 | #define FILENAME_MAX 4096
|
---|
| 64 |
|
---|
[4e6a610] | 65 | /** Length of "/tmp/tmp.XXXXXX" + 1 */
|
---|
| 66 | #define L_tmpnam 16
|
---|
[04b687b] | 67 |
|
---|
[4e6a610] | 68 | #ifndef SEEK_SET
|
---|
| 69 | #define SEEK_SET 0
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
| 72 | #ifndef SEEK_CUR
|
---|
| 73 | #define SEEK_CUR 1
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | #ifndef SEEK_END
|
---|
| 77 | #define SEEK_END 2
|
---|
| 78 | #endif
|
---|
| 79 |
|
---|
| 80 | /** Minimum number of unique temporary file names */
|
---|
| 81 | #define TMP_MAX 1000000
|
---|
[777832e] | 82 |
|
---|
[bc56f30] | 83 | __C_DECLS_BEGIN;
|
---|
| 84 |
|
---|
| 85 | /** Forward declaration */
|
---|
| 86 | struct _IO_FILE;
|
---|
| 87 | typedef struct _IO_FILE FILE;
|
---|
| 88 |
|
---|
| 89 | /** File position */
|
---|
| 90 | typedef struct {
|
---|
| 91 | long long pos;
|
---|
| 92 | } fpos_t;
|
---|
| 93 |
|
---|
[2595dab] | 94 | extern FILE *stdin;
|
---|
| 95 | extern FILE *stdout;
|
---|
| 96 | extern FILE *stderr;
|
---|
| 97 |
|
---|
| 98 | /* Character and string input functions */
|
---|
| 99 | extern int fgetc(FILE *);
|
---|
[c62d2e1] | 100 | extern char *fgets(char *, int, FILE *);
|
---|
[296890f3] | 101 | extern char *gets(char *, size_t) __attribute__((deprecated));
|
---|
[1c1002a] | 102 |
|
---|
[bc56f30] | 103 | static inline int getc(FILE *f)
|
---|
| 104 | {
|
---|
| 105 | return fgetc(f);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[b27a97bb] | 108 | extern int getchar(void);
|
---|
| 109 |
|
---|
[2595dab] | 110 | /* Character and string output functions */
|
---|
[ed88c8e] | 111 | extern int fputc(int, FILE *);
|
---|
[2595dab] | 112 | extern int fputs(const char *, FILE *);
|
---|
| 113 |
|
---|
[bc56f30] | 114 | static inline int putc(int i, FILE *f)
|
---|
| 115 | {
|
---|
| 116 | return fputc(i, f);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[ed88c8e] | 119 | extern int putchar(int);
|
---|
[ab00d5a] | 120 | extern int puts(const char *);
|
---|
[3eddaff] | 121 |
|
---|
[bd5414e] | 122 | extern int ungetc(int, FILE *);
|
---|
| 123 |
|
---|
[ed88c8e] | 124 | extern wint_t fputwc(wchar_t, FILE *);
|
---|
| 125 | extern wint_t putwchar(wchar_t);
|
---|
| 126 |
|
---|
[28a5ebd] | 127 | extern wint_t fputuc(char32_t, FILE *);
|
---|
| 128 | extern wint_t putuchar(char32_t);
|
---|
| 129 |
|
---|
[2595dab] | 130 | /* Formatted string output functions */
|
---|
[1433ecda] | 131 | extern int fprintf(FILE *, const char *, ...)
|
---|
[09d13c8e] | 132 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
---|
[2595dab] | 133 | extern int vfprintf(FILE *, const char *, va_list);
|
---|
[3214a20] | 134 |
|
---|
[9ac2013] | 135 | extern int printf(const char *, ...)
|
---|
[09d13c8e] | 136 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
---|
[ab00d5a] | 137 | extern int vprintf(const char *, va_list);
|
---|
[3214a20] | 138 |
|
---|
[1433ecda] | 139 | extern int snprintf(char *, size_t, const char *, ...)
|
---|
[09d13c8e] | 140 | _HELENOS_PRINTF_ATTRIBUTE(3, 4);
|
---|
[55092672] | 141 | #if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
|
---|
[a9763c6] | 142 | extern int vasprintf(char **, const char *, va_list);
|
---|
[9ac2013] | 143 | extern int asprintf(char **, const char *, ...)
|
---|
[09d13c8e] | 144 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
---|
[296890f3] | 145 | #endif
|
---|
[2595dab] | 146 | extern int vsnprintf(char *, size_t, const char *, va_list);
|
---|
[a8e9ab8d] | 147 |
|
---|
[296890f3] | 148 | extern int sprintf(char *, const char *, ...)
|
---|
| 149 | __attribute__((deprecated)) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
---|
| 150 | extern int vsprintf(char *, const char *, va_list) __attribute__((deprecated));
|
---|
| 151 |
|
---|
[5a6c28d1] | 152 | /* Formatted input */
|
---|
| 153 | extern int scanf(const char *, ...);
|
---|
| 154 | extern int vscanf(const char *, va_list);
|
---|
| 155 | extern int fscanf(FILE *, const char *, ...);
|
---|
| 156 | extern int vfscanf(FILE *, const char *, va_list);
|
---|
| 157 | extern int sscanf(const char *, const char *, ...);
|
---|
| 158 | extern int vsscanf(const char *, const char *, va_list);
|
---|
[ed18e14] | 159 |
|
---|
[2595dab] | 160 | /* File stream functions */
|
---|
[04b687b] | 161 | extern FILE *fopen(const char *, const char *);
|
---|
[80bee81] | 162 | extern FILE *freopen(const char *, const char *, FILE *);
|
---|
[04b687b] | 163 | extern int fclose(FILE *);
|
---|
[2595dab] | 164 |
|
---|
[04b687b] | 165 | extern size_t fread(void *, size_t, size_t, FILE *);
|
---|
| 166 | extern size_t fwrite(const void *, size_t, size_t, FILE *);
|
---|
[2595dab] | 167 |
|
---|
[777832e] | 168 | extern int fgetpos(FILE *, fpos_t *);
|
---|
| 169 | extern int fsetpos(FILE *, const fpos_t *);
|
---|
| 170 |
|
---|
[456c086] | 171 | extern int fseek(FILE *, long, int);
|
---|
[080ad7f] | 172 | extern void rewind(FILE *);
|
---|
[456c086] | 173 | extern long ftell(FILE *);
|
---|
[04b687b] | 174 | extern int feof(FILE *);
|
---|
[2595dab] | 175 |
|
---|
| 176 | extern int fflush(FILE *);
|
---|
[04b687b] | 177 | extern int ferror(FILE *);
|
---|
| 178 | extern void clearerr(FILE *);
|
---|
| 179 |
|
---|
[777832e] | 180 | extern void perror(const char *);
|
---|
| 181 |
|
---|
[58daded] | 182 | extern int setvbuf(FILE *, void *, int, size_t);
|
---|
[7699c21] | 183 | extern void setbuf(FILE *, void *);
|
---|
[ef8bcc6] | 184 |
|
---|
[b942a66] | 185 | /* Misc file functions */
|
---|
| 186 | extern int remove(const char *);
|
---|
[4e6a610] | 187 | extern int rename(const char *, const char *);
|
---|
[b942a66] | 188 |
|
---|
[4e6a610] | 189 | extern FILE *tmpfile(void);
|
---|
[b79903b] | 190 | extern char *tmpnam(char *s);
|
---|
[bc1b297] | 191 |
|
---|
[bc56f30] | 192 | __C_DECLS_END;
|
---|
| 193 |
|
---|
[bc1b297] | 194 | #ifdef _HELENOS_SOURCE
|
---|
| 195 |
|
---|
[bc56f30] | 196 | #include <_bits/off64_t.h>
|
---|
| 197 |
|
---|
| 198 | __HELENOS_DECLS_BEGIN;
|
---|
| 199 |
|
---|
[bc1b297] | 200 | /* Nonstandard extensions. */
|
---|
| 201 |
|
---|
[bc56f30] | 202 | enum __buffer_type {
|
---|
[bc1b297] | 203 | /** No buffering */
|
---|
| 204 | _IONBF,
|
---|
| 205 | /** Line buffering */
|
---|
| 206 | _IOLBF,
|
---|
| 207 | /** Full buffering */
|
---|
| 208 | _IOFBF
|
---|
| 209 | };
|
---|
| 210 |
|
---|
| 211 | extern FILE *fdopen(int, const char *);
|
---|
| 212 | extern int fileno(FILE *);
|
---|
| 213 |
|
---|
[1c7f381] | 214 | extern int fseek64(FILE *, off64_t, int);
|
---|
| 215 | extern off64_t ftell64(FILE *);
|
---|
| 216 |
|
---|
[bc56f30] | 217 | __HELENOS_DECLS_END;
|
---|
[82fd245] | 218 | #endif
|
---|
| 219 |
|
---|
[3eddaff] | 220 | #endif
|
---|
[b2951e2] | 221 |
|
---|
[fadd381] | 222 | /** @}
|
---|
[b2951e2] | 223 | */
|
---|