| 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/uchar.h>
|
|---|
| 45 | #include <_bits/wint_t.h>
|
|---|
| 46 | #include <_bits/decls.h>
|
|---|
| 47 |
|
|---|
| 48 | #ifndef _HELENOS_SOURCE
|
|---|
| 49 | #define _IONBF 0
|
|---|
| 50 | #define _IOLBF 1
|
|---|
| 51 | #define _IOFBF 2
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | /** Default size for stream I/O buffers */
|
|---|
| 55 | #define BUFSIZ 4096
|
|---|
| 56 |
|
|---|
| 57 | #define EOF (-1)
|
|---|
| 58 |
|
|---|
| 59 | /** Max number of files that is guaranteed to be able to open at the same time */
|
|---|
| 60 | #define FOPEN_MAX 16
|
|---|
| 61 |
|
|---|
| 62 | /** Recommended size of fixed-size array for holding file names. */
|
|---|
| 63 | #define FILENAME_MAX 4096
|
|---|
| 64 |
|
|---|
| 65 | /** Length of "/tmp/tmp.XXXXXX" + 1 */
|
|---|
| 66 | #define L_tmpnam 16
|
|---|
| 67 |
|
|---|
| 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
|
|---|
| 82 |
|
|---|
| 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 |
|
|---|
| 94 | extern FILE *stdin;
|
|---|
| 95 | extern FILE *stdout;
|
|---|
| 96 | extern FILE *stderr;
|
|---|
| 97 |
|
|---|
| 98 | /* Character and string input functions */
|
|---|
| 99 | extern int fgetc(FILE *);
|
|---|
| 100 | extern char *fgets(char *, int, FILE *);
|
|---|
| 101 | extern char *gets(char *, size_t) __attribute__((deprecated));
|
|---|
| 102 |
|
|---|
| 103 | static inline int getc(FILE *f)
|
|---|
| 104 | {
|
|---|
| 105 | return fgetc(f);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | extern int getchar(void);
|
|---|
| 109 |
|
|---|
| 110 | /* Character and string output functions */
|
|---|
| 111 | extern int fputc(int, FILE *);
|
|---|
| 112 | extern int fputs(const char *, FILE *);
|
|---|
| 113 |
|
|---|
| 114 | static inline int putc(int i, FILE *f)
|
|---|
| 115 | {
|
|---|
| 116 | return fputc(i, f);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | extern int putchar(int);
|
|---|
| 120 | extern int puts(const char *);
|
|---|
| 121 |
|
|---|
| 122 | extern int ungetc(int, FILE *);
|
|---|
| 123 |
|
|---|
| 124 | extern wint_t fputwc(wchar_t, FILE *);
|
|---|
| 125 | extern wint_t putwchar(wchar_t);
|
|---|
| 126 |
|
|---|
| 127 | extern wint_t fputuc(char32_t, FILE *);
|
|---|
| 128 | extern wint_t putuchar(char32_t);
|
|---|
| 129 |
|
|---|
| 130 | /* Formatted string output functions */
|
|---|
| 131 | extern int fprintf(FILE *, const char *, ...)
|
|---|
| 132 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 133 | extern int vfprintf(FILE *, const char *, va_list);
|
|---|
| 134 |
|
|---|
| 135 | extern int printf(const char *, ...)
|
|---|
| 136 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 137 | extern int vprintf(const char *, va_list);
|
|---|
| 138 |
|
|---|
| 139 | extern int snprintf(char *, size_t, const char *, ...)
|
|---|
| 140 | _HELENOS_PRINTF_ATTRIBUTE(3, 4);
|
|---|
| 141 | #if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
|
|---|
| 142 | extern int vasprintf(char **, const char *, va_list);
|
|---|
| 143 | extern int asprintf(char **, const char *, ...)
|
|---|
| 144 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 145 | #endif
|
|---|
| 146 | extern int vsnprintf(char *, size_t, const char *, va_list);
|
|---|
| 147 |
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 159 |
|
|---|
| 160 | /* File stream functions */
|
|---|
| 161 | extern FILE *fopen(const char *, const char *);
|
|---|
| 162 | extern FILE *freopen(const char *, const char *, FILE *);
|
|---|
| 163 | extern int fclose(FILE *);
|
|---|
| 164 |
|
|---|
| 165 | extern size_t fread(void *, size_t, size_t, FILE *);
|
|---|
| 166 | extern size_t fwrite(const void *, size_t, size_t, FILE *);
|
|---|
| 167 |
|
|---|
| 168 | extern int fgetpos(FILE *, fpos_t *);
|
|---|
| 169 | extern int fsetpos(FILE *, const fpos_t *);
|
|---|
| 170 |
|
|---|
| 171 | extern int fseek(FILE *, long, int);
|
|---|
| 172 | extern void rewind(FILE *);
|
|---|
| 173 | extern long ftell(FILE *);
|
|---|
| 174 | extern int feof(FILE *);
|
|---|
| 175 |
|
|---|
| 176 | extern int fflush(FILE *);
|
|---|
| 177 | extern int ferror(FILE *);
|
|---|
| 178 | extern void clearerr(FILE *);
|
|---|
| 179 |
|
|---|
| 180 | extern void perror(const char *);
|
|---|
| 181 |
|
|---|
| 182 | extern int setvbuf(FILE *, void *, int, size_t);
|
|---|
| 183 | extern void setbuf(FILE *, void *);
|
|---|
| 184 |
|
|---|
| 185 | /* Misc file functions */
|
|---|
| 186 | extern int remove(const char *);
|
|---|
| 187 | extern int rename(const char *, const char *);
|
|---|
| 188 |
|
|---|
| 189 | extern FILE *tmpfile(void);
|
|---|
| 190 | extern char *tmpnam(char *s);
|
|---|
| 191 |
|
|---|
| 192 | __C_DECLS_END;
|
|---|
| 193 |
|
|---|
| 194 | #ifdef _HELENOS_SOURCE
|
|---|
| 195 |
|
|---|
| 196 | #include <_bits/off64_t.h>
|
|---|
| 197 |
|
|---|
| 198 | __HELENOS_DECLS_BEGIN;
|
|---|
| 199 |
|
|---|
| 200 | /* Nonstandard extensions. */
|
|---|
| 201 |
|
|---|
| 202 | enum __buffer_type {
|
|---|
| 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 |
|
|---|
| 214 | extern int fseek64(FILE *, off64_t, int);
|
|---|
| 215 | extern off64_t ftell64(FILE *);
|
|---|
| 216 |
|
|---|
| 217 | __HELENOS_DECLS_END;
|
|---|
| 218 | #endif
|
|---|
| 219 |
|
|---|
| 220 | #endif
|
|---|
| 221 |
|
|---|
| 222 | /** @}
|
|---|
| 223 | */
|
|---|