2 * zioP.h Internal header for libzio, including required
3 * standard glibc header, zlib.h, and bzlib.h.
4 * Making the used libz 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.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Author: Werner Fink <werner@suse.de>
27 #include <sys/types.h>
37 # define unused __attribute__((__unused__))
40 # define nonnull(parm) __attribute__((__nonnull__ parm))
43 # define wur __attribute__((__warn_unused_result__))
45 #define alignof(type) (sizeof(type)+(sizeof(type)%sizeof(void*)))
46 #define strsize(str) ((strlen(str)+1)*sizeof(char))
48 #if !defined(HAVE_FOPENCOOKIE) && !defined(HAVE_FUNOPEN)
49 # error Requires fopencookie(3GNU) or funopen(3BSD)
52 #if defined(HAVE_LIBIO_H) || defined(HAVE_FOPENCOOKIE)
53 # if defined __GLIBC__ && __GLIBC__ > 1
54 # undef LIBIO_IS_FIXED
55 # if __GLIBC__ > 2 || (__GLIBC__ >= 2 && __GLIBC_MINOR__ > 0)
56 # define LIBIO_IS_FIXED
59 # error The libzio requires the GLIBC
64 # if defined __USE_ISOC99
65 # define _cat_pragma(exp) _Pragma(#exp)
66 # define _weak_pragma(exp) _cat_pragma(weak name)
68 # define _weak_pragma(exp)
70 # define _declare(name) __extension__ extern __typeof__(name) name
71 # define weak_symbol(name) _weak_pragma(name) _declare(name) __attribute__((weak))
73 # error The libzio requires the GCC
76 #if defined(HAS_ZLIB_H)
89 #if defined(HAS_BZLIB_H)
92 weak_symbol(BZ2_bzopen);
93 weak_symbol(BZ2_bzdopen);
94 weak_symbol(BZ2_bzread);
95 weak_symbol(BZ2_bzwrite);
97 weak_symbol(BZ2_bzflush);
98 weak_symbol(BZ2_bzclose);
102 #if defined(HAS_LZMA_H)
106 weak_symbol(lzma_easy_encoder);
107 weak_symbol(lzma_lzma_preset);
108 weak_symbol(lzma_alone_encoder);
109 weak_symbol(lzma_auto_decoder);
110 weak_symbol(lzma_code);
111 weak_symbol(lzma_end);
113 #else /* !HAS_LZMA_H */
114 # if defined(HAS_LZMADEC_H)
116 # include <lzmadec.h>
118 weak_symbol(lzmadec_open);
119 weak_symbol(lzmadec_dopen);
120 weak_symbol(lzmadec_read);
121 /* no lzmadec_write() */
122 weak_symbol(lzmadec_seek);
123 weak_symbol(lzmadec_close);
124 /* no lzmadec_flush() */
127 #endif /* !HAS_LZMA_H */
129 #if defined(HAVE_FOPENCOOKIE)
131 __extension__ typedef off_t zio_off_t;
132 __extension__ typedef int zio_int_t;
133 # if !defined(LIBIO_IS_FIXED)
134 __extension__ typedef _IO_cookie_io_functions_t cookie_io_functions_t;
135 __extension__ typedef ssize_t cookie_read_function_t __P ((void *, char *, size_t));
136 __extension__ typedef ssize_t cookie_write_function_t __P ((void *, const char *, size_t));
137 __extension__ typedef int cookie_seek_function_t __P ((void *, off_t, int));
138 __extension__ typedef int cookie_close_function_t __P ((void *));
141 #if defined(HAVE_FUNOPEN)
142 __extension__ typedef size_t zio_off_t;
143 __extension__ typedef fpos_t zio_int_t;
144 __extension__ typedef int cookie_read_function_t __P ((void *, char *, int));
145 __extension__ typedef int cookie_write_function_t __P ((void *, const char *, int));
146 __extension__ typedef fpos_t cookie_seek_function_t __P ((void *, fpos_t, int));
147 __extension__ typedef int cookie_close_function_t __P ((void *));
148 __extension__ typedef struct
150 cookie_read_function_t *read;
151 cookie_write_function_t *write;
152 cookie_seek_function_t *seek;
153 cookie_close_function_t *close;
154 } cookie_io_functions_t;
155 static __inline__ FILE *fopencookie(void *__restrict,
156 const char *__restrict,
157 cookie_io_functions_t) nonnull((1,2)) wur;
158 static __inline__ FILE *fopencookie(void *__restrict cookie,
159 const char *__restrict mode unused,
160 cookie_io_functions_t io_funcs)
162 return funopen(cookie, io_funcs.read, io_funcs.write, io_funcs.seek, io_funcs.close);
165 #endif /* _ZIO_P_H */