- merge in most of the MacOS changes from Dave Abrahams
authorMichael Schroeder <mls@suse.de>
Mon, 24 Jan 2011 14:42:49 +0000 (15:42 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 24 Jan 2011 14:42:49 +0000 (15:42 +0100)
12 files changed:
CMakeLists.txt
examples/solv.c
src/evr.c
src/repodata.c
src/sha1.c
src/sha2.c
src/util.c
tools/common_myfopen.h [new file with mode: 0644]
tools/installcheck.c
tools/patchcheck.c
tools/rpmmd2solv.c
tools/susetags2solv.c

index 24234db..a156295 100644 (file)
@@ -67,6 +67,21 @@ ENDIF ( DB_LIBRARY )
 ENDIF ( FEDORA )
 ENDIF ( NOT DEBIAN )
 
+INCLUDE ( CheckFunctionExists )
+INCLUDE ( TestBigEndian )
+
+CHECK_FUNCTION_EXISTS( strchrnul HAVE_STRCHRNUL )
+CHECK_FUNCTION_EXISTS( fopencookie HAVE_FOPENCOOKIE )
+CHECK_FUNCTION_EXISTS( funopen HAVE_FUNOPEN )
+TEST_BIG_ENDIAN( WORDS_BIGENDIAN )
+
+# should create config.h with #cmakedefine instead...
+FOREACH( VAR HAVE_STRCHRNUL HAVE_FOPENCOOKIE HAVE_FUNOPEN WORDS_BIGENDIAN )
+  IF( ${VAR} )
+    ADD_DEFINITIONS( -D${VAR}=1 )
+  ENDIF( ${VAR} )
+ENDFOREACH( VAR )
+
 SET( PACKAGE "satsolver" )
 SET( VERSION "${LIBSATSOLVER_MAJOR}.${LIBSATSOLVER_MINOR}.${LIBSATSOLVER_PATCH}" )
 
index 636e9ca..8d35117 100644 (file)
@@ -73,6 +73,7 @@
 #include "repo_content.h"
 #include "pool_fileconflicts.h"
 
+#include "../tools/common_myfopen.h"
 
 #ifdef FEDORA
 # define REPOINFO_PATH "/etc/yum.repos.d"
@@ -762,18 +763,6 @@ findmirrorlisturl(FILE *fp)
   return 0;
 }
 
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
-  return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
-  return gzclose((gzFile *)cookie);
-}
-
 FILE *
 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
 {
@@ -872,7 +861,6 @@ curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsign
   if (uncompress)
     {
       char tmpl[100];
-      cookie_io_functions_t cio;
       gzFile *gzf;
 
       sprintf(tmpl, "/dev/fd/%d", fd);
@@ -883,10 +871,7 @@ curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsign
          fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
          exit(1);
        }
-      memset(&cio, 0, sizeof(cio));
-      cio.read = cookie_gzread;
-      cio.close = cookie_gzclose;
-      return fopencookie(gzf, "r", cio);
+      return mygzfopen(gzf);
     }
   fcntl(fd, F_SETFD, FD_CLOEXEC);
   return fdopen(fd, "r");
index a20c7b7..302c9c2 100644 (file)
--- a/src/evr.c
+++ b/src/evr.c
@@ -73,6 +73,8 @@ vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
 #if !defined(DEBIAN_SEMANTICS) || defined(MULTI_SEMANTICS)
 
 /* rpm type version compare */
+/* note: the code assumes that *q1 and *q2 are not alphanumeric! */
+
 int
 vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
 {
@@ -97,7 +99,7 @@ vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
            e1++;
          for (e2 = s2; *e2 >= '0' && *e2 <= '9'; )
            e2++;
-         r = e1 - s1 - (e2 - s2);
+         r = (e1 - s1) - (e2 - s2);
           if (!r)
            r = strncmp(s1, s2, e1 - s1);
           if (r)
@@ -109,7 +111,7 @@ vercmp(const char *s1, const char *q1, const char *s2, const char *q2)
            e1++;
          for (e2 = s2; (*e2 >= 'a' && *e2 <= 'z') || (*e2 >= 'A' && *e2 <= 'Z'); )
            e2++;
-         r = e1 - s1 - (e2 - s2);
+         r = (e1 - s1) - (e2 - s2);
           if (r > 0)
            {
              r = strncmp(s1, s2, e2 - s2);
index 4fa2aa7..39cea01 100644 (file)
@@ -231,6 +231,14 @@ repodata_free_schemahash(Repodata *data)
  * dir pool management
  */
 
+#ifndef HAVE_STRCHRNUL
+static inline const char *strchrnul(const char *str, char x)
+{
+  const char *p = strchr(str, x);
+  return p ? p : str + strlen(str);
+}
+#endif
+
 Id
 repodata_str2dir(Repodata *data, const char *dir, int create)
 {
index 52f74d9..a8361d9 100644 (file)
@@ -78,7 +78,6 @@ A million repetitions of "a"
 
 #include <stdio.h>
 #include <string.h>
-#include <endian.h>
 #include "sha1.h"
 
 
@@ -89,7 +88,7 @@ static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]);
 /* blk0() and blk() perform the initial expand. */
 /* I got the idea of expanding during the round function from SSLeay */
 /* FIXME: can we do this in an endian-proof way? */
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
 #define blk0(i) block.l[i]
 #else
 #define blk0(i) (block.l[i] = (rol(block.l[i],24)&0xFF00FF00) \
index 5b36016..a9cf41b 100644 (file)
@@ -40,7 +40,6 @@
 #include <sys/uio.h>
 #include <unistd.h>
 #include <inttypes.h>
-#include <endian.h>
 
 #include "sha2.h"
 
@@ -96,9 +95,6 @@
  * <machine/endian.h> where the appropriate definitions are actually
  * made).
  */
-#if !defined(__BYTE_ORDER) || (__BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN)
-#error Define __BYTE_ORDER to be equal to either __LITTLE_ENDIAN or __BIG_ENDIAN
-#endif
 
 /*
  * Define the following sha2_* types to types of the correct length on
@@ -127,7 +123,7 @@ typedef uint64_t sha2_word64;       /* Exactly 8 bytes */
 
 
 /*** ENDIAN REVERSAL MACROS *******************************************/
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
 #define REVERSE32(w,x) { \
        sha2_word32 tmp = (w); \
        tmp = (tmp >> 16) | (tmp << 16); \
@@ -141,7 +137,7 @@ typedef uint64_t sha2_word64;       /* Exactly 8 bytes */
        (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
              ((tmp & 0x0000ffff0000ffffULL) << 16); \
 }
-#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* !WORDS_BIGENDIAN */
 
 /*
  * Macro for incrementally adding the unsigned 64-bit integer n to the
@@ -347,7 +343,7 @@ void sat_SHA256_Init(SHA256_CTX* context) {
 
 /* Unrolled SHA-256 round macros: */
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
 
 #define ROUND256_0_TO_15(a,b,c,d,e,f,g,h)      \
        REVERSE32(*data++, W256[j]); \
@@ -358,7 +354,7 @@ void sat_SHA256_Init(SHA256_CTX* context) {
        j++
 
 
-#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#else /* !WORDS_BIGENDIAN */
 
 #define ROUND256_0_TO_15(a,b,c,d,e,f,g,h)      \
        T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
@@ -367,7 +363,7 @@ void sat_SHA256_Init(SHA256_CTX* context) {
        (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
        j++
 
-#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* !WORDS_BIGENDIAN */
 
 #define ROUND256(a,b,c,d,e,f,g,h)      \
        s0 = W256[(j+1)&0x0f]; \
@@ -457,15 +453,15 @@ static void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
 
        j = 0;
        do {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                /* Copy data while converting to host byte order */
                REVERSE32(*data++,W256[j]);
                /* Apply the SHA-256 compression function to update a..h */
                T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
-#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#else /* !WORDS_BIGENDIAN */
                /* Apply the SHA-256 compression function to update a..h with copy */
                T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
-#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* !WORDS_BIGENDIAN */
                T2 = Sigma0_256(a) + Maj(a, b, c);
                h = g;
                g = f;
@@ -576,7 +572,7 @@ void sat_SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
        /* If no digest buffer is passed, we don't bother doing this: */
        if (digest != (sha2_byte*)0) {
                usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                /* Convert FROM host byte order */
                REVERSE64(context->bitcount,context->bitcount);
 #endif
@@ -610,7 +606,7 @@ void sat_SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
                /* Final transform: */
                SHA256_Transform(context, (sha2_word32*)context->buffer);
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                {
                        /* Convert TO host byte order */
                        int     j;
@@ -674,7 +670,7 @@ void sat_SHA512_Init(SHA512_CTX* context) {
 #ifdef SHA2_UNROLL_TRANSFORM
 
 /* Unrolled SHA-512 round macros: */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
 
 #define ROUND512_0_TO_15(a,b,c,d,e,f,g,h)      \
        REVERSE64(*data++, W512[j]); \
@@ -685,7 +681,7 @@ void sat_SHA512_Init(SHA512_CTX* context) {
        j++
 
 
-#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#else /* !WORDS_BIGENDIAN */
 
 #define ROUND512_0_TO_15(a,b,c,d,e,f,g,h)      \
        T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
@@ -694,7 +690,7 @@ void sat_SHA512_Init(SHA512_CTX* context) {
        (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
        j++
 
-#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* !WORDS_BIGENDIAN */
 
 #define ROUND512(a,b,c,d,e,f,g,h)      \
        s0 = W512[(j+1)&0x0f]; \
@@ -779,15 +775,15 @@ static void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
 
        j = 0;
        do {
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                /* Convert TO host byte order */
                REVERSE64(*data++, W512[j]);
                /* Apply the SHA-512 compression function to update a..h */
                T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
-#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#else /* !WORDS_BIGENDIAN */
                /* Apply the SHA-512 compression function to update a..h with copy */
                T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
-#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* !WORDS_BIGENDIAN */
                T2 = Sigma0_512(a) + Maj(a, b, c);
                h = g;
                g = f;
@@ -892,7 +888,7 @@ static void SHA512_Last(SHA512_CTX* context) {
        unsigned int    usedspace;
 
        usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
        /* Convert FROM host byte order */
        REVERSE64(context->bitcount[0],context->bitcount[0]);
        REVERSE64(context->bitcount[1],context->bitcount[1]);
@@ -940,7 +936,7 @@ void sat_SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
                SHA512_Last(context);
 
                /* Save the hash data for output: */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                {
                        /* Convert TO host byte order */
                        int     j;
@@ -1015,7 +1011,7 @@ void sat_SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
                SHA512_Last((SHA512_CTX*)context);
 
                /* Save the hash data for output: */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
                {
                        /* Convert TO host byte order */
                        int     j;
index 0538432..294930f 100644 (file)
@@ -114,7 +114,7 @@ sat_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, cons
   __qsort_r(base, nmemb, size, compar, compard);
 # endif
 #else
-# error please add qsort_r call here
+# error please add correct qsort_r call here, note different ordering on BSD
 #endif
 }
 
diff --git a/tools/common_myfopen.h b/tools/common_myfopen.h
new file mode 100644 (file)
index 0000000..0a52aa7
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_COMMON_MYFOPEN_H
+#define SATSOLVER_COMMON_MYFOPEN_H
+
+static ssize_t cookie_gzread(void *cookie, char *buf, size_t nbytes)
+{
+  return gzread((gzFile *)cookie, buf, nbytes);
+}
+
+static int
+cookie_gzclose(void *cookie)
+{
+  return gzclose((gzFile *)cookie);
+}
+
+static FILE *mygzfopen(gzFile* gzf)
+{
+#ifdef HAVE_FUNOPEN
+  return funopen(
+      gzf, (int (*)(void *, char *, int))cookie_gzread,
+      (int (*)(void *, const char *, int))NULL, /* writefn */
+      (fpos_t (*)(void *, fpos_t, int))NULL, /* seekfn */
+      cookie_gzclose
+      );
+#elif defined(HAVE_FOPENCOOKIE)
+  cookie_io_functions_t cio;
+  memset(&cio, 0, sizeof(cio));
+  cio.read = cookie_gzread;
+  cio.close = cookie_gzclose;
+  return  fopencookie(gzf, "r", cio);
+#else
+# error Need to implement custom I/O
+#endif
+}
+
+FILE *
+myfopen(const char *fn)
+{
+  char *suf;
+  gzFile *gzf;
+
+  if (!fn)
+    return 0;
+  suf = strrchr(fn, '.');
+  if (!suf || strcmp(suf, ".gz") != 0)
+    return fopen(fn, "r");
+  gzf = gzopen(fn, "r");
+  if (!gzf)
+    return 0;
+  return mygzfopen(gzf);
+}
+
+#endif /* SATSOLVER_COMMON_MYFOPEN_H */
index b1ebb5e..459b411 100644 (file)
 #include "repo_deb.h"
 #endif
 #include "solver.h"
+#include "common_myfopen.h"
 
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
-  return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
-  return gzclose((gzFile *)cookie);
-}
-
-FILE *
-myfopen(const char *fn)
-{
-  cookie_io_functions_t cio;
-  char *suf;
-  gzFile *gzf;
-
-  if (!fn)
-    return 0;
-  suf = strrchr(fn, '.');
-  if (!suf || strcmp(suf, ".gz") != 0)
-    return fopen(fn, "r");
-  gzf = gzopen(fn, "r");
-  if (!gzf)
-    return 0;
-  memset(&cio, 0, sizeof(cio));
-  cio.read = cookie_gzread;
-  cio.close = cookie_gzclose;
-  return  fopencookie(gzf, "r", cio);
-}
 
 void
 usage(char** argv)
index 1d92da4..90b5ee0 100644 (file)
 #include "solver.h"
 #include "solverdebug.h"
 
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
-  return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
-  return gzclose((gzFile *)cookie);
-}
-
-FILE *
-myfopen(const char *fn)
-{
-  cookie_io_functions_t cio;
-  char *suf;
-  gzFile *gzf;
-
-  if (!fn)
-    return 0;
-  suf = strrchr(fn, '.');
-  if (!suf || strcmp(suf, ".gz") != 0)
-    return fopen(fn, "r");
-  gzf = gzopen(fn, "r");
-  if (!gzf)
-    return 0;
-  memset(&cio, 0, sizeof(cio));
-  cio.read = cookie_gzread;
-  cio.close = cookie_gzclose;
-  return  fopencookie(gzf, "r", cio);
-}
+#include "common_myfopen.h"
 
 void
 showproblems(Solver *solv, Solvable *s, Queue *cand, Queue *badguys)
index e5c2c84..834f490 100644 (file)
 #include "repo.h"
 #include "repo_rpmmd.h"
 #include "common_write.h"
+#include "common_myfopen.h"
 
 
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
-  return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
-  return gzclose((gzFile *)cookie);
-}
-
-FILE *
-myfopen(const char *fn)
-{
-  cookie_io_functions_t cio;
-  char *suf;
-  gzFile *gzf;
-
-  if (!fn)
-    return 0;
-  suf = strrchr(fn, '.');
-  if (!suf || strcmp(suf, ".gz") != 0)
-    return fopen(fn, "r");
-  gzf = gzopen(fn, "r");
-  if (!gzf)
-    return 0;
-  memset(&cio, 0, sizeof(cio));
-  cio.read = cookie_gzread;
-  cio.close = cookie_gzclose;
-  return  fopencookie(gzf, "r", cio);
-}
-
 static void
 usage(int status)
 {
index a0fd08e..9ba54db 100644 (file)
@@ -22,6 +22,7 @@
 #include "repo_susetags.h"
 #include "repo_content.h"
 #include "common_write.h"
+#include "common_myfopen.h"
 
 static void
 usage(int status)
@@ -38,39 +39,6 @@ usage(int status)
    exit(status);
 }
 
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
-  return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
-  return gzclose((gzFile *)cookie);
-}
-
-FILE *
-myfopen(const char *fn)
-{
-  cookie_io_functions_t cio;
-  char *suf;
-  gzFile *gzf;
-
-  if (!fn)
-    return 0;
-  suf = strrchr(fn, '.');
-  if (!suf || strcmp(suf, ".gz") != 0)
-    return fopen(fn, "r");
-  gzf = gzopen(fn, "r");
-  if (!gzf)
-    return 0;
-  memset(&cio, 0, sizeof(cio));
-  cio.read = cookie_gzread;
-  cio.close = cookie_gzclose;
-  return  fopencookie(gzf, "r", cio);
-}
-
 /* content file query */
 static void
 doquery(Pool *pool, Repo *repo, const char *arg)