| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2005 Martin Decky
|
|---|
| 3 | * SPDX-FileCopyrightText: 2018 Jiri Svoboda
|
|---|
| 4 | *
|
|---|
| 5 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /** @addtogroup libc
|
|---|
| 9 | * @{
|
|---|
| 10 | */
|
|---|
| 11 | /** @file
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #ifndef _LIBC_STDIO_H_
|
|---|
| 15 | #define _LIBC_STDIO_H_
|
|---|
| 16 |
|
|---|
| 17 | #include <stdarg.h>
|
|---|
| 18 | #include <io/verify.h>
|
|---|
| 19 | #include <_bits/NULL.h>
|
|---|
| 20 | #include <_bits/size_t.h>
|
|---|
| 21 | #include <_bits/wchar_t.h>
|
|---|
| 22 | #include <_bits/uchar.h>
|
|---|
| 23 | #include <_bits/wint_t.h>
|
|---|
| 24 | #include <_bits/decls.h>
|
|---|
| 25 |
|
|---|
| 26 | #ifndef _HELENOS_SOURCE
|
|---|
| 27 | #define _IONBF 0
|
|---|
| 28 | #define _IOLBF 1
|
|---|
| 29 | #define _IOFBF 2
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | /** Default size for stream I/O buffers */
|
|---|
| 33 | #define BUFSIZ 4096
|
|---|
| 34 |
|
|---|
| 35 | #define EOF (-1)
|
|---|
| 36 |
|
|---|
| 37 | /** Max number of files that is guaranteed to be able to open at the same time */
|
|---|
| 38 | #define FOPEN_MAX 16
|
|---|
| 39 |
|
|---|
| 40 | /** Recommended size of fixed-size array for holding file names. */
|
|---|
| 41 | #define FILENAME_MAX 4096
|
|---|
| 42 |
|
|---|
| 43 | /** Length of "/tmp/tmp.XXXXXX" + 1 */
|
|---|
| 44 | #define L_tmpnam 16
|
|---|
| 45 |
|
|---|
| 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
|
|---|
| 60 |
|
|---|
| 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 |
|
|---|
| 72 | extern FILE *stdin;
|
|---|
| 73 | extern FILE *stdout;
|
|---|
| 74 | extern FILE *stderr;
|
|---|
| 75 |
|
|---|
| 76 | /* Character and string input functions */
|
|---|
| 77 | extern int fgetc(FILE *);
|
|---|
| 78 | extern char *fgets(char *, int, FILE *);
|
|---|
| 79 | extern char *gets(char *, size_t) __attribute__((deprecated));
|
|---|
| 80 |
|
|---|
| 81 | static inline int getc(FILE *f)
|
|---|
| 82 | {
|
|---|
| 83 | return fgetc(f);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | extern int getchar(void);
|
|---|
| 87 |
|
|---|
| 88 | /* Character and string output functions */
|
|---|
| 89 | extern int fputc(int, FILE *);
|
|---|
| 90 | extern int fputs(const char *, FILE *);
|
|---|
| 91 |
|
|---|
| 92 | static inline int putc(int i, FILE *f)
|
|---|
| 93 | {
|
|---|
| 94 | return fputc(i, f);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | extern int putchar(int);
|
|---|
| 98 | extern int puts(const char *);
|
|---|
| 99 |
|
|---|
| 100 | extern int ungetc(int, FILE *);
|
|---|
| 101 |
|
|---|
| 102 | extern wint_t fputwc(wchar_t, FILE *);
|
|---|
| 103 | extern wint_t putwchar(wchar_t);
|
|---|
| 104 |
|
|---|
| 105 | extern wint_t fputuc(char32_t, FILE *);
|
|---|
| 106 | extern wint_t putuchar(char32_t);
|
|---|
| 107 |
|
|---|
| 108 | /* Formatted string output functions */
|
|---|
| 109 | extern int fprintf(FILE *, const char *, ...)
|
|---|
| 110 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 111 | extern int vfprintf(FILE *, const char *, va_list);
|
|---|
| 112 |
|
|---|
| 113 | extern int printf(const char *, ...)
|
|---|
| 114 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 115 | extern int vprintf(const char *, va_list);
|
|---|
| 116 |
|
|---|
| 117 | extern int snprintf(char *, size_t, const char *, ...)
|
|---|
| 118 | _HELENOS_PRINTF_ATTRIBUTE(3, 4);
|
|---|
| 119 | #if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
|
|---|
| 120 | extern int vasprintf(char **, const char *, va_list);
|
|---|
| 121 | extern int asprintf(char **, const char *, ...)
|
|---|
| 122 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 123 | #endif
|
|---|
| 124 | extern int vsnprintf(char *, size_t, const char *, va_list);
|
|---|
| 125 |
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 137 |
|
|---|
| 138 | /* File stream functions */
|
|---|
| 139 | extern FILE *fopen(const char *, const char *);
|
|---|
| 140 | extern FILE *freopen(const char *, const char *, FILE *);
|
|---|
| 141 | extern int fclose(FILE *);
|
|---|
| 142 |
|
|---|
| 143 | extern size_t fread(void *, size_t, size_t, FILE *);
|
|---|
| 144 | extern size_t fwrite(const void *, size_t, size_t, FILE *);
|
|---|
| 145 |
|
|---|
| 146 | extern int fgetpos(FILE *, fpos_t *);
|
|---|
| 147 | extern int fsetpos(FILE *, const fpos_t *);
|
|---|
| 148 |
|
|---|
| 149 | extern int fseek(FILE *, long, int);
|
|---|
| 150 | extern void rewind(FILE *);
|
|---|
| 151 | extern long ftell(FILE *);
|
|---|
| 152 | extern int feof(FILE *);
|
|---|
| 153 |
|
|---|
| 154 | extern int fflush(FILE *);
|
|---|
| 155 | extern int ferror(FILE *);
|
|---|
| 156 | extern void clearerr(FILE *);
|
|---|
| 157 |
|
|---|
| 158 | extern void perror(const char *);
|
|---|
| 159 |
|
|---|
| 160 | extern int setvbuf(FILE *, void *, int, size_t);
|
|---|
| 161 | extern void setbuf(FILE *, void *);
|
|---|
| 162 |
|
|---|
| 163 | /* Misc file functions */
|
|---|
| 164 | extern int remove(const char *);
|
|---|
| 165 | extern int rename(const char *, const char *);
|
|---|
| 166 |
|
|---|
| 167 | extern FILE *tmpfile(void);
|
|---|
| 168 | extern char *tmpnam(char *s);
|
|---|
| 169 |
|
|---|
| 170 | __C_DECLS_END;
|
|---|
| 171 |
|
|---|
| 172 | #ifdef _HELENOS_SOURCE
|
|---|
| 173 |
|
|---|
| 174 | #include <_bits/off64_t.h>
|
|---|
| 175 |
|
|---|
| 176 | __HELENOS_DECLS_BEGIN;
|
|---|
| 177 |
|
|---|
| 178 | /* Nonstandard extensions. */
|
|---|
| 179 |
|
|---|
| 180 | enum __buffer_type {
|
|---|
| 181 | /** No buffering */
|
|---|
| 182 | _IONBF,
|
|---|
| 183 | /** Line buffering */
|
|---|
| 184 | _IOLBF,
|
|---|
| 185 | /** Full buffering */
|
|---|
| 186 | _IOFBF
|
|---|
| 187 | };
|
|---|
| 188 |
|
|---|
| 189 | extern int vprintf_length(const char *, va_list);
|
|---|
| 190 | extern int printf_length(const char *, ...)
|
|---|
| 191 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 192 | extern FILE *fdopen(int, const char *);
|
|---|
| 193 | extern int fileno(FILE *);
|
|---|
| 194 |
|
|---|
| 195 | extern int fseek64(FILE *, off64_t, int);
|
|---|
| 196 | extern off64_t ftell64(FILE *);
|
|---|
| 197 |
|
|---|
| 198 | __HELENOS_DECLS_END;
|
|---|
| 199 | #endif
|
|---|
| 200 |
|
|---|
| 201 | #endif
|
|---|
| 202 |
|
|---|
| 203 | /** @}
|
|---|
| 204 | */
|
|---|