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