| 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 */
|
|---|
| 85 | struct _IO_FILE;
|
|---|
| 86 | typedef struct _IO_FILE FILE;
|
|---|
| 87 |
|
|---|
| 88 | /** File position */
|
|---|
| 89 | typedef struct {
|
|---|
| 90 | long long pos;
|
|---|
| 91 | } fpos_t;
|
|---|
| 92 |
|
|---|
| 93 | extern FILE *stdin;
|
|---|
| 94 | extern FILE *stdout;
|
|---|
| 95 | extern FILE *stderr;
|
|---|
| 96 |
|
|---|
| 97 | /* Character and string input functions */
|
|---|
| 98 | extern int fgetc(FILE *);
|
|---|
| 99 | extern char *fgets(char *, int, FILE *);
|
|---|
| 100 | extern char *gets(char *, size_t) __attribute__((deprecated));
|
|---|
| 101 |
|
|---|
| 102 | static inline int getc(FILE *f)
|
|---|
| 103 | {
|
|---|
| 104 | return fgetc(f);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | extern int getchar(void);
|
|---|
| 108 |
|
|---|
| 109 | /* Character and string output functions */
|
|---|
| 110 | extern int fputc(int, FILE *);
|
|---|
| 111 | extern int fputs(const char *, FILE *);
|
|---|
| 112 |
|
|---|
| 113 | static inline int putc(int i, FILE *f)
|
|---|
| 114 | {
|
|---|
| 115 | return fputc(i, f);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | extern int putchar(int);
|
|---|
| 119 | extern int puts(const char *);
|
|---|
| 120 |
|
|---|
| 121 | extern int ungetc(int, FILE *);
|
|---|
| 122 |
|
|---|
| 123 | extern wint_t fputwc(wchar_t, FILE *);
|
|---|
| 124 | extern wint_t putwchar(wchar_t);
|
|---|
| 125 |
|
|---|
| 126 | /* Formatted string output functions */
|
|---|
| 127 | extern int fprintf(FILE *, const char *, ...)
|
|---|
| 128 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 129 | extern int vfprintf(FILE *, const char *, va_list);
|
|---|
| 130 |
|
|---|
| 131 | extern int printf(const char *, ...)
|
|---|
| 132 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 133 | extern int vprintf(const char *, va_list);
|
|---|
| 134 |
|
|---|
| 135 | extern int snprintf(char *, size_t, const char *, ...)
|
|---|
| 136 | _HELENOS_PRINTF_ATTRIBUTE(3, 4);
|
|---|
| 137 | #if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
|
|---|
| 138 | extern int vasprintf(char **, const char *, va_list);
|
|---|
| 139 | extern int asprintf(char **, const char *, ...)
|
|---|
| 140 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 141 | #endif
|
|---|
| 142 | extern int vsnprintf(char *, size_t, const char *, va_list);
|
|---|
| 143 |
|
|---|
| 144 | extern int sprintf(char *, const char *, ...)
|
|---|
| 145 | __attribute__((deprecated)) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 146 | extern int vsprintf(char *, const char *, va_list) __attribute__((deprecated));
|
|---|
| 147 |
|
|---|
| 148 | /* Formatted input */
|
|---|
| 149 | extern int scanf(const char *, ...);
|
|---|
| 150 | extern int vscanf(const char *, va_list);
|
|---|
| 151 | extern int fscanf(FILE *, const char *, ...);
|
|---|
| 152 | extern int vfscanf(FILE *, const char *, va_list);
|
|---|
| 153 | extern int sscanf(const char *, const char *, ...);
|
|---|
| 154 | extern int vsscanf(const char *, const char *, va_list);
|
|---|
| 155 |
|
|---|
| 156 | /* File stream functions */
|
|---|
| 157 | extern FILE *fopen(const char *, const char *);
|
|---|
| 158 | extern FILE *freopen(const char *, const char *, FILE *);
|
|---|
| 159 | extern int fclose(FILE *);
|
|---|
| 160 |
|
|---|
| 161 | extern size_t fread(void *, size_t, size_t, FILE *);
|
|---|
| 162 | extern size_t fwrite(const void *, size_t, size_t, FILE *);
|
|---|
| 163 |
|
|---|
| 164 | extern int fgetpos(FILE *, fpos_t *);
|
|---|
| 165 | extern int fsetpos(FILE *, const fpos_t *);
|
|---|
| 166 |
|
|---|
| 167 | extern int fseek(FILE *, long, int);
|
|---|
| 168 | extern void rewind(FILE *);
|
|---|
| 169 | extern long ftell(FILE *);
|
|---|
| 170 | extern int feof(FILE *);
|
|---|
| 171 |
|
|---|
| 172 | extern int fflush(FILE *);
|
|---|
| 173 | extern int ferror(FILE *);
|
|---|
| 174 | extern void clearerr(FILE *);
|
|---|
| 175 |
|
|---|
| 176 | extern void perror(const char *);
|
|---|
| 177 |
|
|---|
| 178 | extern int setvbuf(FILE *, void *, int, size_t);
|
|---|
| 179 | extern void setbuf(FILE *, void *);
|
|---|
| 180 |
|
|---|
| 181 | /* Misc file functions */
|
|---|
| 182 | extern int remove(const char *);
|
|---|
| 183 | extern int rename(const char *, const char *);
|
|---|
| 184 |
|
|---|
| 185 | extern FILE *tmpfile(void);
|
|---|
| 186 | extern 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 |
|
|---|
| 198 | enum __buffer_type {
|
|---|
| 199 | /** No buffering */
|
|---|
| 200 | _IONBF,
|
|---|
| 201 | /** Line buffering */
|
|---|
| 202 | _IOLBF,
|
|---|
| 203 | /** Full buffering */
|
|---|
| 204 | _IOFBF
|
|---|
| 205 | };
|
|---|
| 206 |
|
|---|
| 207 | extern int vprintf_length(const char *, va_list);
|
|---|
| 208 | extern int printf_length(const char *, ...)
|
|---|
| 209 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 210 | extern FILE *fdopen(int, const char *);
|
|---|
| 211 | extern int fileno(FILE *);
|
|---|
| 212 |
|
|---|
| 213 | extern int fseek64(FILE *, off64_t, int);
|
|---|
| 214 | extern off64_t ftell64(FILE *);
|
|---|
| 215 |
|
|---|
| 216 | __HELENOS_DECLS_END;
|
|---|
| 217 | #endif
|
|---|
| 218 |
|
|---|
| 219 | #endif
|
|---|
| 220 |
|
|---|
| 221 | /** @}
|
|---|
| 222 | */
|
|---|