1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
13 #ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
14 #error no custom streams!
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. */
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. */
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
31 /* Currently no real reentrancy issues other than a possible double close(). */
34 /* libc_hidden_proto(fopencookie) */
35 FILE *fopencookie(void * __restrict cookie, const char * __restrict mode,
36 cookie_io_functions_t io_functions)
38 FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode,
39 register cookie_io_functions_t *io_functions)
44 /* Fake an fdopen guaranteed to pass the _stdio_fopen basic agreement
45 * check without an fcntl call. */
46 stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, NULL, INT_MAX);
48 stream->__filedes = -1;
50 stream->__gcs = io_functions;
52 stream->__gcs.read = io_functions->read;
53 stream->__gcs.write = io_functions->write;
54 stream->__gcs.seek = io_functions->seek;
55 stream->__gcs.close = io_functions->close;
57 stream->__cookie = cookie;
59 __STDIO_STREAM_VALIDATE(stream);
65 libc_hidden_def(fopencookie)