| 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 | #ifdef __cplusplus
|
|---|
| 40 | extern "C" {
|
|---|
| 41 | #endif
|
|---|
| 42 |
|
|---|
| 43 | #include <offset.h>
|
|---|
| 44 | #include <stdarg.h>
|
|---|
| 45 | #include <io/verify.h>
|
|---|
| 46 | #include <_bits/NULL.h>
|
|---|
| 47 | #include <_bits/size_t.h>
|
|---|
| 48 | #include <_bits/wchar_t.h>
|
|---|
| 49 | #include <_bits/wint_t.h>
|
|---|
| 50 |
|
|---|
| 51 | /** Forward declaration */
|
|---|
| 52 | struct _IO_FILE;
|
|---|
| 53 | typedef struct _IO_FILE FILE;
|
|---|
| 54 |
|
|---|
| 55 | /** File position */
|
|---|
| 56 | typedef struct {
|
|---|
| 57 | off64_t pos;
|
|---|
| 58 | } fpos_t;
|
|---|
| 59 |
|
|---|
| 60 | #ifndef _HELENOS_SOURCE
|
|---|
| 61 | #define _IONBF 0
|
|---|
| 62 | #define _IOLBF 1
|
|---|
| 63 | #define _IOFBF 2
|
|---|
| 64 | #endif
|
|---|
| 65 |
|
|---|
| 66 | /** Default size for stream I/O buffers */
|
|---|
| 67 | #define BUFSIZ 4096
|
|---|
| 68 |
|
|---|
| 69 | #define EOF (-1)
|
|---|
| 70 |
|
|---|
| 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 |
|
|---|
| 74 | /** Recommended size of fixed-size array for holding file names. */
|
|---|
| 75 | #define FILENAME_MAX 4096
|
|---|
| 76 |
|
|---|
| 77 | /** Length of "/tmp/tmp.XXXXXX" + 1 */
|
|---|
| 78 | #define L_tmpnam 16
|
|---|
| 79 |
|
|---|
| 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
|
|---|
| 94 |
|
|---|
| 95 | extern FILE *stdin;
|
|---|
| 96 | extern FILE *stdout;
|
|---|
| 97 | extern FILE *stderr;
|
|---|
| 98 |
|
|---|
| 99 | /* Character and string input functions */
|
|---|
| 100 | #define getc fgetc
|
|---|
| 101 | extern int fgetc(FILE *);
|
|---|
| 102 | extern char *fgets(char *, int, FILE *);
|
|---|
| 103 | extern char *gets(char *, size_t) __attribute__((deprecated));
|
|---|
| 104 |
|
|---|
| 105 | extern int getchar(void);
|
|---|
| 106 |
|
|---|
| 107 | /* Character and string output functions */
|
|---|
| 108 | #define putc fputc
|
|---|
| 109 | extern int fputc(int, FILE *);
|
|---|
| 110 | extern int fputs(const char *, FILE *);
|
|---|
| 111 |
|
|---|
| 112 | extern int putchar(int);
|
|---|
| 113 | extern int puts(const char *);
|
|---|
| 114 |
|
|---|
| 115 | extern int ungetc(int, FILE *);
|
|---|
| 116 |
|
|---|
| 117 | extern wint_t fputwc(wchar_t, FILE *);
|
|---|
| 118 | extern wint_t putwchar(wchar_t);
|
|---|
| 119 |
|
|---|
| 120 | /* Formatted string output functions */
|
|---|
| 121 | extern int fprintf(FILE *, const char *, ...)
|
|---|
| 122 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 123 | extern int vfprintf(FILE *, const char *, va_list);
|
|---|
| 124 |
|
|---|
| 125 | extern int printf(const char *, ...)
|
|---|
| 126 | _HELENOS_PRINTF_ATTRIBUTE(1, 2);
|
|---|
| 127 | extern int vprintf(const char *, va_list);
|
|---|
| 128 |
|
|---|
| 129 | extern int snprintf(char *, size_t, const char *, ...)
|
|---|
| 130 | _HELENOS_PRINTF_ATTRIBUTE(3, 4);
|
|---|
| 131 | #if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
|
|---|
| 132 | extern int vasprintf(char **, const char *, va_list);
|
|---|
| 133 | extern int asprintf(char **, const char *, ...)
|
|---|
| 134 | _HELENOS_PRINTF_ATTRIBUTE(2, 3);
|
|---|
| 135 | #endif
|
|---|
| 136 | extern int vsnprintf(char *, size_t, const char *, va_list);
|
|---|
| 137 |
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 149 |
|
|---|
| 150 | /* File stream functions */
|
|---|
| 151 | extern FILE *fopen(const char *, const char *);
|
|---|
| 152 | extern FILE *freopen(const char *, const char *, FILE *);
|
|---|
| 153 | extern int fclose(FILE *);
|
|---|
| 154 |
|
|---|
| 155 | extern size_t fread(void *, size_t, size_t, FILE *);
|
|---|
| 156 | extern size_t fwrite(const void *, size_t, size_t, FILE *);
|
|---|
| 157 |
|
|---|
| 158 | extern int fgetpos(FILE *, fpos_t *);
|
|---|
| 159 | extern int fsetpos(FILE *, const fpos_t *);
|
|---|
| 160 |
|
|---|
| 161 | extern int fseek(FILE *, long, int);
|
|---|
| 162 | extern void rewind(FILE *);
|
|---|
| 163 | extern long ftell(FILE *);
|
|---|
| 164 | extern int feof(FILE *);
|
|---|
| 165 |
|
|---|
| 166 | extern int fflush(FILE *);
|
|---|
| 167 | extern int ferror(FILE *);
|
|---|
| 168 | extern void clearerr(FILE *);
|
|---|
| 169 |
|
|---|
| 170 | extern void perror(const char *);
|
|---|
| 171 |
|
|---|
| 172 | extern void setvbuf(FILE *, void *, int, size_t);
|
|---|
| 173 | extern void setbuf(FILE *, void *);
|
|---|
| 174 |
|
|---|
| 175 | /* Misc file functions */
|
|---|
| 176 | extern int remove(const char *);
|
|---|
| 177 | extern int rename(const char *, const char *);
|
|---|
| 178 |
|
|---|
| 179 | extern FILE *tmpfile(void);
|
|---|
| 180 | extern char *tmpnam(char *s) __attribute__((deprecated));
|
|---|
| 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 |
|
|---|
| 212 | #include <offset.h>
|
|---|
| 213 |
|
|---|
| 214 | extern int fseek64(FILE *, off64_t, int);
|
|---|
| 215 | extern off64_t ftell64(FILE *);
|
|---|
| 216 |
|
|---|
| 217 | #endif
|
|---|
| 218 |
|
|---|
| 219 | #ifdef __cplusplus
|
|---|
| 220 | }
|
|---|
| 221 | #endif
|
|---|
| 222 |
|
|---|
| 223 | #endif
|
|---|
| 224 |
|
|---|
| 225 | /** @}
|
|---|
| 226 | */
|
|---|