#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <zlib.h>
#include <fcntl.h>
#include "solv_xfopen.h"
#include "util.h"
-/* Evil hack for Haiku: fopencookie() is implemented internally, but not
- exported by a header. */
-#ifdef __HAIKU__
-
-typedef struct {
- ssize_t (*read)(void*, char*, size_t);
- ssize_t (*write)(void*, const char*, size_t);
- int (*seek)(off_t*, int);
- int (*close)(void*);
-} cookie_io_functions_t;
-
-
-FILE *fopencookie(void*, const char*, cookie_io_functions_t);
-
-#endif /* __HAIKU__ */
-
-
static FILE *cookieopen(void *cookie, const char *mode,
ssize_t (*cread)(void *, char *, size_t),
ssize_t (*cwrite)(void *, const char *, size_t),
}
+#ifdef ENABLE_ZLIB_COMPRESSION
+
/* gzip compression */
+#include <zlib.h>
+
static ssize_t cookie_gzread(void *cookie, char *buf, size_t nbytes)
{
return gzread((gzFile)cookie, buf, nbytes);
return cookieopen(gzf, mode, cookie_gzread, cookie_gzwrite, cookie_gzclose);
}
-#ifdef ENABLE_BZIP2_COMPRESSION
+#endif
-#include <bzlib.h>
+
+#ifdef ENABLE_BZIP2_COMPRESSION
/* bzip2 compression */
+#include <bzlib.h>
+
static ssize_t cookie_bzread(void *cookie, char *buf, size_t nbytes)
{
return BZ2_bzread((BZFILE *)cookie, buf, nbytes);
#ifdef ENABLE_LZMA_COMPRESSION
-#include <lzma.h>
-
/* lzma code written by me in 2008 for rpm's rpmio.c */
+#include <lzma.h>
+
typedef struct lzfile {
unsigned char buf[1 << 15];
lzma_stream strm;
if (!mode)
mode = "r";
suf = strrchr(fn, '.');
+#ifdef ENABLE_ZLIB_COMPRESSION
if (suf && !strcmp(suf, ".gz"))
return mygzfopen(fn, mode);
+#else
+ if (suf && !strcmp(suf, ".gz"))
+ return 0;
+#endif
#ifdef ENABLE_LZMA_COMPRESSION
if (suf && !strcmp(suf, ".xz"))
return myxzfopen(fn, mode);
else
mode = simplemode = "r";
}
+#ifdef ENABLE_ZLIB_COMPRESSION
if (suf && !strcmp(suf, ".gz"))
return mygzfdopen(fd, simplemode);
+#else
+ if (suf && !strcmp(suf, ".gz"))
+ return 0;
+#endif
#ifdef ENABLE_LZMA_COMPRESSION
if (suf && !strcmp(suf, ".xz"))
return myxzfdopen(fd, simplemode);
const char *suf = fn ? strrchr(fn, '.') : 0;
if (!suf)
return 0;
+#ifdef ENABLE_ZLIB_COMPRESSION
if (!strcmp(suf, ".gz"))
return 1;
+#else
+ return -1;
+#endif
if (!strcmp(suf, ".xz") || !strcmp(suf, ".lzma"))
#ifdef ENABLE_LZMA_COMPRESSION
return 1;