lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org> |
| 2 | * |
| 3 | * GNU Library General Public License (LGPL) version 2 or later. |
| 4 | * |
| 5 | * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details. |
| 6 | */ |
| 7 | |
| 8 | #include <features.h> |
| 9 | |
| 10 | #ifdef __USE_GNU |
| 11 | #include "_stdio.h" |
| 12 | |
| 13 | #ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ |
| 14 | #error no custom streams! |
| 15 | #endif |
| 16 | |
| 17 | /* NOTE: GLIBC difference!!! -- fopencookie |
| 18 | * According to the info pages, glibc allows seeking within buffers even if |
| 19 | * no seek function is supplied. We don't. */ |
| 20 | |
| 21 | /* NOTE: GLIBC difference!!! -- fopencookie |
| 22 | * When compiled without large file support, the offset pointer for the |
| 23 | * cookie_seek function is off_t * and not off64_t * as for glibc. */ |
| 24 | |
| 25 | /* NOTE: GLIBC difference!!! -- fopencookie (bcc only) |
| 26 | * Since bcc doesn't support passing of structs, we define fopencookie as a |
| 27 | * macro in terms of _fopencookie which takes a struct * for the io functions |
| 28 | * instead. |
| 29 | */ |
| 30 | |
| 31 | /* Currently no real reentrancy issues other than a possible double close(). */ |
| 32 | |
| 33 | #ifndef __BCC__ |
| 34 | FILE *fopencookie(void * __restrict cookie, const char * __restrict mode, |
| 35 | cookie_io_functions_t io_functions) |
| 36 | #else |
| 37 | FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode, |
| 38 | register cookie_io_functions_t *io_functions) |
| 39 | #endif |
| 40 | { |
| 41 | FILE *stream; |
| 42 | |
| 43 | /* Fake an fdopen guaranteed to pass the _stdio_fopen basic agreement |
| 44 | * check without an fcntl call. */ |
| 45 | stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, NULL, INT_MAX); |
| 46 | if (stream) { |
| 47 | stream->__filedes = -1; |
| 48 | #ifndef __BCC__ |
| 49 | stream->__gcs = io_functions; |
| 50 | #else |
| 51 | stream->__gcs.read = io_functions->read; |
| 52 | stream->__gcs.write = io_functions->write; |
| 53 | stream->__gcs.seek = io_functions->seek; |
| 54 | stream->__gcs.close = io_functions->close; |
| 55 | #endif |
| 56 | stream->__cookie = cookie; |
| 57 | |
| 58 | __STDIO_STREAM_VALIDATE(stream); |
| 59 | } |
| 60 | |
| 61 | return stream; |
| 62 | } |
| 63 | #ifndef __BCC__ |
| 64 | libc_hidden_def(fopencookie) |
| 65 | #endif |
| 66 | #endif |