]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Allow to build libsolv without stdio cookie opens
authorMichael Schroeder <mls@suse.de>
Mon, 1 Apr 2019 14:20:33 +0000 (16:20 +0200)
committerMichael Schroeder <mls@suse.de>
Mon, 1 Apr 2019 14:20:33 +0000 (16:20 +0200)
CMakeLists.txt
ext/solv_xfopen.c
ext/testcase.c

index 8b87c5492a4c0e53d9ee86382e3f56cfeb2f9232..fd9e05595527726762f6e032157360adabe28f59 100644 (file)
@@ -38,6 +38,7 @@ OPTION (ENABLE_ZSTD_COMPRESSION "Build with zstd compression support?" OFF)
 OPTION (ENABLE_ZCHUNK_COMPRESSION "Build with zchunk compression support?" OFF)
 OPTION (WITH_SYSTEM_ZCHUNK "Use system zchunk library?" OFF)
 OPTION (WITH_LIBXML2  "Build with libxml2 instead of libexpat?" OFF)
+OPTION (WITHOUT_COOKIEOPEN "Disable the use of stdio cookie opens?" OFF)
 
 include (GNUInstallDirs)
 message (STATUS "Libraries will be installed in ${CMAKE_INSTALL_FULL_LIBDIR}")
@@ -267,7 +268,7 @@ ENDIF (${CMAKE_MAJOR_VERSION} GREATER 2)
 
 # should create config.h with #cmakedefine instead...
 FOREACH (VAR HAVE_STRCHRNUL HAVE_FOPENCOOKIE HAVE_FUNOPEN WORDS_BIGENDIAN
-  HAVE_RPM_DB_H HAVE_PGPDIGGETPARAMS WITH_LIBXML2 )
+  HAVE_RPM_DB_H HAVE_PGPDIGGETPARAMS WITH_LIBXML2 WITHOUT_COOKIEOPEN)
   IF(${VAR})
     ADD_DEFINITIONS (-D${VAR}=1)
     SET (SWIG_FLAGS ${SWIG_FLAGS} -D${VAR})
index 343aed86834afb78f073118a88ab96c417109e29..d5a04f5f6d2875b12f54ede3cf1127cd02486082 100644 (file)
@@ -15,6 +15,7 @@
 #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),
@@ -602,6 +603,16 @@ static inline FILE *myzchunkfdopen(int fd, const char *mode)
 
 #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)
@@ -759,6 +770,9 @@ solv_xfopen_iscompressed(const char *fn)
   return 0;
 }
 
+
+#ifndef WITHOUT_COOKIEOPEN
+
 struct bufcookie {
   char **bufp;
   size_t *buflp;
@@ -835,3 +849,32 @@ solv_xfopen_buf(const char *fn, char **bufp, size_t *buflp, const char *mode)
     }
   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 + 1, "r+")))
+       return 0;
+      if (l && fwrite(*bufp, l, 1, fp) != 1)
+       {
+         fclose(fp);
+         return 0;
+       }
+      rewind(fp);
+    }
+  else
+    fp = fmemopen(*bufp, l, "r");
+  return fp;
+}
+
+#endif
+
index 8edf58ff58c4083c685fdbd7e6fd2441c37c000c..5c54bbf918caa1bd98667934fe340c27064e72bb 100644 (file)
@@ -2199,7 +2199,11 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
        sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
       else
        sprintf(priobuf, "%d", repo->priority);
+#if !defined(WITHOUT_COOKIEOPEN) && defined(ENABLE_ZLIB_COMPRESSION)
       out = pool_tmpjoin(pool, name, ".repo", ".gz");
+#else
+      out = pool_tmpjoin(pool, name, ".repo", 0);
+#endif
       for (i = 0; out[i]; i++)
        if (out[i] == '/')
          out[i] = '_';