#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <sys/time.h>
+#include <fcntl.h>
+#ifdef _WIN32
+ #include <windows.h>
+ #include <io.h>
+#else
+ #include <sys/time.h>
+#endif
#include "util.h"
return r;
}
+/* this was solv_realloc2(old, len, size), but we now overshoot
+ * for huge len sizes */
+void *
+solv_extend_realloc(void *old, size_t len, size_t size, size_t block)
+{
+ size_t xblock = (block + 1) << 5;
+ len = (len + block) & ~block;
+ if (len >= xblock && xblock)
+ {
+ xblock <<= 1;
+ while (len >= xblock && xblock)
+ xblock <<= 1;
+ if (xblock)
+ {
+ size_t nlen;
+ xblock = (xblock >> 5) - 1;
+ nlen = (len + xblock) & ~xblock;
+ if (nlen > len)
+ len = nlen;
+ }
+ }
+ return solv_realloc2(old, len, size);
+}
+
void *
solv_free(void *mem)
{
unsigned int
solv_timems(unsigned int subtract)
{
+#ifdef _WIN32
+ return GetTickCount() - subtract;
+#else
struct timeval tv;
unsigned int r;
r += ((unsigned int)tv.tv_sec & 0xffff) * 1000;
r += (unsigned int)tv.tv_usec / 1000;
return r - subtract;
+#endif
+}
+
+int
+solv_setcloexec(int fd, int state)
+{
+ #ifdef _WIN32
+ return SetHandleInformation((HANDLE) _get_osfhandle(fd), HANDLE_FLAG_INHERIT, state ? 0 : HANDLE_FLAG_INHERIT);
+ #else
+ return fcntl(fd, F_SETFD, state ? FD_CLOEXEC : 0) == 0;
+ #endif
}
/* bsd's qsort_r has different arguments, so we define our
see also: http://sources.redhat.com/ml/libc-alpha/2008-12/msg00003.html
*/
-#if defined(__GLIBC__) && (defined(HAVE_QSORT_R) || defined(HAVE___QSORT_R))
+#if (defined(__GLIBC__) || defined(__NEWLIB__)) && (defined(HAVE_QSORT_R) || defined(HAVE___QSORT_R))
void
solv_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *compard)
d = c - ('A' - 10);
else
break;
- c = *++str;
+ c = str[1];
d <<= 4;
if (c >= '0' && c <= '9')
d |= c - '0';
else
break;
buf[i] = d;
- ++str;
+ str += 2;
}
*strp = str;
return i;