2 * zioP.h Internal header for libzio, including required standard glibc
3 * header, zlib.h, lzma.h or lzmadec.h, and bzlib.h.
4 * Making the used libz, liblzma, and bzlib functions weak symbols.
6 * Copyright 2004 Werner Fink, 2004 SuSE LINUX AG, Germany.
7 * Copyright 2006 Werner Fink, 2006 SuSE Products GmbH, Germany.
8 * Copyright 2013 Werner Fink, 2013 SuSE Products GmbH, Germany.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Author: Werner Fink <werner@suse.de>
36 #include <sys/types.h>
46 # define unused __attribute__((__unused__))
49 # define nonnull(parm) __attribute__((__nonnull__ parm))
52 # define wur __attribute__((__warn_unused_result__))
54 #define alignof(type) (sizeof(type)+(sizeof(type)%sizeof(void*)))
55 #define strsize(str) ((strlen(str)+1)*sizeof(char))
57 #if !defined(HAVE_FOPENCOOKIE) && !defined(HAVE_FUNOPEN)
58 # error Requires fopencookie(3GNU) or funopen(3BSD)
61 #if defined(HAVE_LIBIO_H) || defined(HAVE_FOPENCOOKIE)
62 # if defined __GLIBC__ && __GLIBC__ > 1
63 # undef LIBIO_IS_FIXED
64 # if __GLIBC__ > 2 || (__GLIBC__ >= 2 && __GLIBC_MINOR__ > 0)
65 # define LIBIO_IS_FIXED
68 # error The libzio requires the GLIBC
73 # if defined __USE_ISOC99
74 # define _cat_pragma(exp) _Pragma(#exp)
75 # define _weak_pragma(exp) _cat_pragma(weak name)
77 # define _weak_pragma(exp)
79 # define _declare(name) __extension__ extern __typeof__(name) name
80 # define weak_symbol(name) _weak_pragma(name) _declare(name) __attribute__((weak))
82 # error The libzio requires the GCC
85 #if defined(HAS_ZLIB_H)
98 #if defined(HAS_BZLIB_H)
101 weak_symbol(BZ2_bzopen);
102 weak_symbol(BZ2_bzdopen);
103 weak_symbol(BZ2_bzread);
104 weak_symbol(BZ2_bzwrite);
106 weak_symbol(BZ2_bzflush);
107 weak_symbol(BZ2_bzclose);
111 #if defined(HAS_LZMA_H)
115 weak_symbol(lzma_easy_encoder);
116 weak_symbol(lzma_lzma_preset);
117 weak_symbol(lzma_alone_encoder);
118 weak_symbol(lzma_auto_decoder);
119 weak_symbol(lzma_code);
120 weak_symbol(lzma_end);
122 #else /* !HAS_LZMA_H */
123 # if defined(HAS_LZMADEC_H)
125 # include <lzmadec.h>
127 weak_symbol(lzmadec_open);
128 weak_symbol(lzmadec_dopen);
129 weak_symbol(lzmadec_read);
130 /* no lzmadec_write() */
131 weak_symbol(lzmadec_seek);
132 weak_symbol(lzmadec_close);
133 /* no lzmadec_flush() */
136 #endif /* !HAS_LZMA_H */
138 #if defined(HAVE_FOPENCOOKIE)
140 __extension__ typedef off_t zio_off_t;
141 __extension__ typedef int zio_int_t;
142 # if !defined(LIBIO_IS_FIXED)
143 __extension__ typedef _IO_cookie_io_functions_t cookie_io_functions_t;
144 __extension__ typedef ssize_t cookie_read_function_t __P ((void *, char *, size_t));
145 __extension__ typedef ssize_t cookie_write_function_t __P ((void *, const char *, size_t));
146 __extension__ typedef int cookie_seek_function_t __P ((void *, off_t, int));
147 __extension__ typedef int cookie_close_function_t __P ((void *));
150 #if defined(HAVE_FUNOPEN)
151 __extension__ typedef size_t zio_off_t;
152 __extension__ typedef fpos_t zio_int_t;
153 __extension__ typedef int cookie_read_function_t __P ((void *, char *, int));
154 __extension__ typedef int cookie_write_function_t __P ((void *, const char *, int));
155 __extension__ typedef fpos_t cookie_seek_function_t __P ((void *, fpos_t, int));
156 __extension__ typedef int cookie_close_function_t __P ((void *));
157 __extension__ typedef struct
159 cookie_read_function_t *read;
160 cookie_write_function_t *write;
161 cookie_seek_function_t *seek;
162 cookie_close_function_t *close;
163 } cookie_io_functions_t;
164 static __inline__ FILE *fopencookie(void *__restrict,
165 const char *__restrict,
166 cookie_io_functions_t) nonnull((1,2)) wur;
167 static __inline__ FILE *fopencookie(void *__restrict cookie,
168 const char *__restrict mode unused,
169 cookie_io_functions_t io_funcs)
171 return funopen(cookie, io_funcs.read, io_funcs.write, io_funcs.seek, io_funcs.close);
174 #endif /* _ZIO_P_H */