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