OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / stdio / fopencookie.c
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 /* libc_hidden_proto(fopencookie) */
35 FILE *fopencookie(void * __restrict cookie, const char * __restrict mode,
36                                   cookie_io_functions_t io_functions)
37 #else
38 FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode,
39                                    register cookie_io_functions_t *io_functions)
40 #endif
41 {
42         FILE *stream;
43
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);
47         if (stream) {
48                 stream->__filedes = -1;
49 #ifndef __BCC__
50                 stream->__gcs = io_functions;
51 #else
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;
56 #endif
57                 stream->__cookie = cookie;
58
59                 __STDIO_STREAM_VALIDATE(stream);
60         }
61
62         return stream;
63 }
64 #ifndef __BCC__
65 libc_hidden_def(fopencookie)
66 #endif
67 #endif