X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;h=99dd5707899f14d805db4c00ce58efdb7678e4b3;hp=614e09d5f5c21202b9e6fc6bf45b1a3597633e74;hb=8d09bf022eb055d175b8b4642df7f8dd5e4e9e19;hpb=715d32a47773ed1ed2c157e6ff24111a2160842e diff --git a/miscutil.c b/miscutil.c index 614e09d5..99dd5707 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.59 2008/09/04 08:13:58 fabiankeil Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.61 2008/10/18 11:09:23 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -44,6 +44,12 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.59 2008/09/04 08:13:58 fabianke * * Revisions : * $Log: miscutil.c,v $ + * Revision 1.61 2008/10/18 11:09:23 fabiankeil + * Improve seed used by pick_from_range() on mingw32. + * + * Revision 1.60 2008/09/07 12:35:05 fabiankeil + * Add mutex lock support for _WIN32. + * * Revision 1.59 2008/09/04 08:13:58 fabiankeil * Prepare for critical sections on Windows by adding a * layer of indirection before the pthread mutex functions. @@ -553,7 +559,7 @@ int strcmpic(const char *s1, const char *s2) *********************************************************************/ int strncmpic(const char *s1, const char *s2, size_t n) { - if (n <= 0) return(0); + if (n <= (size_t)0) return(0); if (!s1) s1 = ""; if (!s2) s2 = ""; @@ -564,7 +570,7 @@ int strncmpic(const char *s1, const char *s2, size_t n) break; } - if (--n <= 0) break; + if (--n <= (size_t)0) break; s1++, s2++; } @@ -758,7 +764,7 @@ jb_err string_join(char **target_string, char *text_to_append) err = string_append(target_string, text_to_append); - free(text_to_append); + freez(text_to_append); return err; } @@ -968,6 +974,9 @@ char * make_path(const char * dir, const char * file) long int pick_from_range(long int range) { long int number; +#ifdef _WIN32 + static unsigned long seed = 0; +#endif /* def _WIN32 */ assert(range != 0); assert(range > 0); @@ -979,9 +988,14 @@ long int pick_from_range(long int range) #elif defined(MUTEX_LOCKS_AVAILABLE) privoxy_mutex_lock(&rand_mutex); #ifdef _WIN32 - srand((unsigned)(GetCurrentThreadId()+GetTickCount())); + if (!seed) + { + seed = (unsigned long)(GetCurrentThreadId()+GetTickCount()); + } + srand(seed); + seed = (unsigned long)((rand() << 16) + rand()); #endif /* def _WIN32 */ - number = rand() % (long int)(range + 1); + number = (unsigned long)((rand() << 16) + (rand())) % (unsigned long)(range + 1); privoxy_mutex_unlock(&rand_mutex); #else /*