#include <string.h>
#include <fcntl.h>
+#ifdef _WIN32
+ #include "fmemopen.c"
+#endif
+
#include "solv_xfopen.h"
#include "util.h"
+#ifndef WITHOUT_COOKIEOPEN
static FILE *cookieopen(void *cookie, const char *mode,
ssize_t (*cread)(void *, char *, size_t),
#endif /* ENABLE_ZCHUNK_COMPRESSION */
+#else
+/* no cookies no compression */
+#undef ENABLE_ZLIB_COMPRESSION
+#undef ENABLE_LZMA_COMPRESSION
+#undef ENABLE_BZIP2_COMPRESSION
+#undef ENABLE_ZSTD_COMPRESSION
+#undef ENABLE_ZCHUNK_COMPRESSION
+#endif
+
+
FILE *
solv_xfopen(const char *fn, const char *mode)
suf = fn ? strrchr(fn, '.') : 0;
if (!mode)
{
+ #ifndef _WIN32
int fl = fcntl(fd, F_GETFL, 0);
+ #else
+ HANDLE handle = (HANDLE) _get_osfhandle(fd);
+ BY_HANDLE_FILE_INFORMATION file_info;
+ if (!GetFileInformationByHandle(handle, &file_info))
+ return 0;
+ int fl = file_info.dwFileAttributes;
+ #endif
if (fl == -1)
return 0;
fl &= O_RDONLY|O_WRONLY|O_RDWR;
return 0;
}
+
+#ifndef WITHOUT_COOKIEOPEN
+
struct bufcookie {
char **bufp;
size_t *buflp;
}
return fp;
}
+
+#else
+
+FILE *
+solv_xfopen_buf(const char *fn, char **bufp, size_t *buflp, const char *mode)
+{
+ FILE *fp;
+ size_t l;
+ if (*mode != 'r')
+ return 0;
+ l = buflp ? *buflp : strlen(*bufp);
+ if (!strcmp(mode, "rf"))
+ {
+ if (!(fp = fmemopen(0, l, "r+")))
+ return 0;
+ if (l && fwrite(*bufp, l, 1, fp) != 1)
+ {
+ fclose(fp);
+ return 0;
+ }
+ solv_free(*bufp);
+ rewind(fp);
+ }
+ else
+ fp = fmemopen(*bufp, l, "r");
+ return fp;
+}
+
+#endif
+