[3a3ef72] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jiri Zarevucky
|
---|
[4f4b4e7] | 3 | * Copyright (c) 2011 Petr Koupy
|
---|
[3a3ef72] | 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 |
|
---|
[4f4b4e7] | 30 | /** @addtogroup libposix
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
[4cf8ca6] | 33 | /** @file Standard buffered input/output.
|
---|
[4f4b4e7] | 34 | */
|
---|
| 35 |
|
---|
[3a3ef72] | 36 | #ifndef POSIX_STDIO_H_
|
---|
| 37 | #define POSIX_STDIO_H_
|
---|
| 38 |
|
---|
| 39 | #include "libc/stdio.h"
|
---|
[b08ef1fd] | 40 | #include "sys/types.h"
|
---|
[823a929] | 41 | #include "libc/stdarg.h"
|
---|
[8b5fb5e] | 42 | #include "limits.h"
|
---|
[3a3ef72] | 43 |
|
---|
[46ac986] | 44 | /* Identifying the Terminal */
|
---|
[8b5fb5e] | 45 | #undef L_ctermid
|
---|
| 46 | #define L_ctermid PATH_MAX
|
---|
[46ac986] | 47 | extern char *posix_ctermid(char *s);
|
---|
[8b5fb5e] | 48 |
|
---|
[46ac986] | 49 | /* Error Recovery */
|
---|
[8b5fb5e] | 50 | extern void posix_clearerr(FILE *stream);
|
---|
| 51 |
|
---|
| 52 | /* Input/Output */
|
---|
[e3891262] | 53 | #undef putc
|
---|
[3a3ef72] | 54 | #define putc fputc
|
---|
[221afc9e] | 55 | extern int posix_fputs(const char *restrict s, FILE *restrict stream);
|
---|
[e3891262] | 56 | #undef getc
|
---|
[09b0b1fb] | 57 | #define getc fgetc
|
---|
[59f799b] | 58 | extern int posix_ungetc(int c, FILE *stream);
|
---|
[8b5fb5e] | 59 | extern ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n,
|
---|
| 60 | int delimiter, FILE *restrict stream);
|
---|
| 61 | extern ssize_t posix_getline(char **restrict lineptr, size_t *restrict n,
|
---|
| 62 | FILE *restrict stream);
|
---|
| 63 |
|
---|
[4f4b4e7] | 64 | /* Opening Streams */
|
---|
[46ac986] | 65 | extern FILE *posix_freopen(const char *restrict filename,
|
---|
| 66 | const char *restrict mode, FILE *restrict stream);
|
---|
[8b5fb5e] | 67 |
|
---|
[4f4b4e7] | 68 | /* Error Messages */
|
---|
[09b0b1fb] | 69 | extern void posix_perror(const char *s);
|
---|
| 70 |
|
---|
[b08ef1fd] | 71 | /* File Positioning */
|
---|
[8b5fb5e] | 72 | typedef struct _posix_fpos posix_fpos_t;
|
---|
| 73 | extern int posix_fsetpos(FILE *stream, const posix_fpos_t *pos);
|
---|
| 74 | extern int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos);
|
---|
| 75 | extern int posix_fseek(FILE *stream, long offset, int whence);
|
---|
[b08ef1fd] | 76 | extern int posix_fseeko(FILE *stream, posix_off_t offset, int whence);
|
---|
[8b5fb5e] | 77 | extern long posix_ftell(FILE *stream);
|
---|
[b08ef1fd] | 78 | extern posix_off_t posix_ftello(FILE *stream);
|
---|
| 79 |
|
---|
[221afc9e] | 80 | /* Flushing Buffers */
|
---|
| 81 | extern int posix_fflush(FILE *stream);
|
---|
| 82 |
|
---|
[46ac986] | 83 | /* Formatted Output */
|
---|
[8b5fb5e] | 84 | extern int posix_dprintf(int fildes, const char *restrict format, ...)
|
---|
| 85 | PRINTF_ATTRIBUTE(2, 3);
|
---|
| 86 | extern int posix_vdprintf(int fildes, const char *restrict format, va_list ap);
|
---|
| 87 | extern int posix_sprintf(char *restrict s, const char *restrict format, ...)
|
---|
| 88 | PRINTF_ATTRIBUTE(2, 3);
|
---|
[823a929] | 89 | extern int posix_vsprintf(char *restrict s, const char *restrict format, va_list ap);
|
---|
[8b5fb5e] | 90 |
|
---|
[46ac986] | 91 | /* Formatted Input */
|
---|
[8b5fb5e] | 92 | extern int posix_fscanf(
|
---|
| 93 | FILE *restrict stream, const char *restrict format, ...);
|
---|
| 94 | extern int posix_vfscanf(
|
---|
| 95 | FILE *restrict stream, const char *restrict format, va_list arg);
|
---|
| 96 | extern int posix_scanf(const char *restrict format, ...);
|
---|
| 97 | extern int posix_vscanf(const char *restrict format, va_list arg);
|
---|
| 98 | extern int posix_sscanf(
|
---|
| 99 | const char *restrict s, const char *restrict format, ...);
|
---|
| 100 | extern int posix_vsscanf(
|
---|
| 101 | const char *restrict s, const char *restrict format, va_list arg);
|
---|
| 102 |
|
---|
| 103 | /* File Locking */
|
---|
| 104 | extern void posix_flockfile(FILE *file);
|
---|
| 105 | extern int posix_ftrylockfile(FILE *file);
|
---|
| 106 | extern void posix_funlockfile(FILE *file);
|
---|
| 107 | extern int posix_getc_unlocked(FILE *stream);
|
---|
| 108 | extern int posix_getchar_unlocked(void);
|
---|
| 109 | extern int posix_putc_unlocked(int c, FILE *stream);
|
---|
| 110 | extern int posix_putchar_unlocked(int c);
|
---|
[59f799b] | 111 |
|
---|
[823a929] | 112 | /* Deleting Files */
|
---|
| 113 | extern int posix_remove(const char *path);
|
---|
| 114 |
|
---|
[75406dc] | 115 | /* Renaming Files */
|
---|
| 116 | extern int posix_rename(const char *old, const char *new);
|
---|
| 117 |
|
---|
[823a929] | 118 | /* Temporary Files */
|
---|
[e3891262] | 119 | #undef L_tmpnam
|
---|
| 120 | #define L_tmpnam PATH_MAX
|
---|
[823a929] | 121 | extern char *posix_tmpnam(char *s);
|
---|
[11544f4] | 122 | extern char *posix_tempnam(const char *dir, const char *pfx);
|
---|
| 123 | extern FILE *posix_tmpfile(void);
|
---|
[823a929] | 124 |
|
---|
[491e1ee] | 125 | #ifndef LIBPOSIX_INTERNAL
|
---|
[9a6034a] | 126 | /* DEBUG macro does not belong to POSIX stdio.h. Its unconditional
|
---|
| 127 | * definition in the native stdio.h causes unexpected behaviour of
|
---|
| 128 | * applications which uses their own DEBUG macro (e.g. debugging
|
---|
| 129 | * output is printed even if not desirable). */
|
---|
| 130 | #undef DEBUG
|
---|
| 131 |
|
---|
[8b5fb5e] | 132 | #define ctermid posix_ctermid
|
---|
| 133 |
|
---|
[46ac986] | 134 | #define clearerr posix_clearerr
|
---|
[59f799b] | 135 |
|
---|
[221afc9e] | 136 | #define fputs posix_fputs
|
---|
[46ac986] | 137 | #define ungetc posix_ungetc
|
---|
[8b5fb5e] | 138 | #define getdelim posix_getdelim
|
---|
| 139 | #define getline posix_getline
|
---|
| 140 |
|
---|
[09b0b1fb] | 141 | #define freopen posix_freopen
|
---|
[8b5fb5e] | 142 | #define fmemopen posix_fmemopen
|
---|
| 143 | #define open_memstream posix_open_memstream
|
---|
| 144 |
|
---|
[09b0b1fb] | 145 | #define perror posix_perror
|
---|
[b08ef1fd] | 146 |
|
---|
[8b5fb5e] | 147 | #define fpos_t posix_fpos_t
|
---|
| 148 | #define fsetpos posix_fsetpos
|
---|
| 149 | #define fgetpos posix_fgetpos
|
---|
| 150 | #define fseek posix_fseek
|
---|
[b08ef1fd] | 151 | #define fseeko posix_fseeko
|
---|
[8b5fb5e] | 152 | #define ftell posix_ftell
|
---|
[b08ef1fd] | 153 | #define ftello posix_ftello
|
---|
[59f799b] | 154 |
|
---|
[221afc9e] | 155 | #define fflush posix_fflush
|
---|
| 156 |
|
---|
[8b5fb5e] | 157 | #define dprintf posix_dprintf
|
---|
| 158 | #define vdprintf posix_vdprintf
|
---|
[59f799b] | 159 | #define sprintf posix_sprintf
|
---|
[823a929] | 160 | #define vsprintf posix_vsprintf
|
---|
[8b5fb5e] | 161 |
|
---|
| 162 | #define fscanf posix_fscanf
|
---|
| 163 | #define vfscanf posix_vfscanf
|
---|
| 164 | #define vscanf posix_vscanf
|
---|
| 165 | #define scanf posix_scanf
|
---|
[59f799b] | 166 | #define sscanf posix_sscanf
|
---|
[8b5fb5e] | 167 | #define vsscanf posix_vsscanf
|
---|
| 168 |
|
---|
| 169 | #define flockfile posix_flockfile
|
---|
| 170 | #define ftrylockfile posix_ftrylockfile
|
---|
| 171 | #define funlockfile posix_funlockfile
|
---|
| 172 |
|
---|
| 173 | #define getc_unlocked posix_getc_unlocked
|
---|
| 174 | #define getchar_unlocked posix_getchar_unlocked
|
---|
| 175 | #define putc_unlocked posix_putc_unlocked
|
---|
| 176 | #define putchar_unlocked posix_putchar_unlocked
|
---|
[823a929] | 177 |
|
---|
| 178 | #define remove posix_remove
|
---|
| 179 |
|
---|
[75406dc] | 180 | #define rename posix_rename
|
---|
| 181 |
|
---|
[823a929] | 182 | #define tmpnam posix_tmpnam
|
---|
[11544f4] | 183 | #define tempnam posix_tempnam
|
---|
| 184 | #define tmpfile posix_tmpfile
|
---|
[09b0b1fb] | 185 | #endif
|
---|
[3a3ef72] | 186 |
|
---|
| 187 | #endif /* POSIX_STDIO_H_ */
|
---|
| 188 |
|
---|
[4f4b4e7] | 189 | /** @}
|
---|
| 190 | */
|
---|