From: Michael Schroeder Date: Mon, 24 Jan 2011 14:42:49 +0000 (+0100) Subject: - merge in most of the MacOS changes from Dave Abrahams X-Git-Tag: BASE-SuSE-Code-12_1-Branch~151^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ce303515581edcfaf3d82d8392c4508a8aeafd7;p=thirdparty%2Flibsolv.git - merge in most of the MacOS changes from Dave Abrahams --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 24234db3..a1562959 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}" ) diff --git a/examples/solv.c b/examples/solv.c index 636e9ca3..8d351175 100644 --- a/examples/solv.c +++ b/examples/solv.c @@ -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"); diff --git a/src/evr.c b/src/evr.c index a20c7b7a..302c9c27 100644 --- 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); diff --git a/src/repodata.c b/src/repodata.c index 4fa2aa76..39cea014 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -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) { diff --git a/src/sha1.c b/src/sha1.c index 52f74d9b..a8361d97 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -78,7 +78,6 @@ A million repetitions of "a" #include #include -#include #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) \ diff --git a/src/sha2.c b/src/sha2.c index 5b36016a..a9cf41bd 100644 --- a/src/sha2.c +++ b/src/sha2.c @@ -40,7 +40,6 @@ #include #include #include -#include #include "sha2.h" @@ -96,9 +95,6 @@ * 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; diff --git a/src/util.c b/src/util.c index 0538432d..294930fb 100644 --- a/src/util.c +++ b/src/util.c @@ -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 index 00000000..0a52aa70 --- /dev/null +++ b/tools/common_myfopen.h @@ -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 */ diff --git a/tools/installcheck.c b/tools/installcheck.c index b1ebb5e6..459b4111 100644 --- a/tools/installcheck.c +++ b/tools/installcheck.c @@ -27,39 +27,8 @@ #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) diff --git a/tools/patchcheck.c b/tools/patchcheck.c index 1d92da43..90b5ee0f 100644 --- a/tools/patchcheck.c +++ b/tools/patchcheck.c @@ -26,38 +26,7 @@ #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) diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index e5c2c84d..834f4901 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -20,41 +20,9 @@ #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) { diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index a0fd08e3..9ba54db0 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -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)