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}" )
#include "repo_content.h"
#include "pool_fileconflicts.h"
+#include "../tools/common_myfopen.h"
#ifdef FEDORA
# define REPOINFO_PATH "/etc/yum.repos.d"
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)
{
if (uncompress)
{
char tmpl[100];
- cookie_io_functions_t cio;
gzFile *gzf;
sprintf(tmpl, "/dev/fd/%d", fd);
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");
#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)
{
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)
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);
* 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)
{
#include <stdio.h>
#include <string.h>
-#include <endian.h>
#include "sha1.h"
/* 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) \
#include <sys/uio.h>
#include <unistd.h>
#include <inttypes.h>
-#include <endian.h>
#include "sha2.h"
* <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
/*** ENDIAN REVERSAL MACROS *******************************************/
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
#define REVERSE32(w,x) { \
sha2_word32 tmp = (w); \
tmp = (tmp >> 16) | (tmp << 16); \
(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
/* 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]); \
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)) + \
(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]; \
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;
/* 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
/* Final transform: */
SHA256_Transform(context, (sha2_word32*)context->buffer);
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
{
/* Convert TO host byte order */
int j;
#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]); \
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)) + \
(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]; \
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;
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]);
SHA512_Last(context);
/* Save the hash data for output: */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifndef WORDS_BIGENDIAN
{
/* Convert TO host byte order */
int j;
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;
__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
}
--- /dev/null
+/*
+ * 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 */
#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)
#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)
#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)
{
#include "repo_susetags.h"
#include "repo_content.h"
#include "common_write.h"
+#include "common_myfopen.h"
static void
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)