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