lockfile: replace random() by rand()

On Windows, we do not have functions srandom() and random(). Use srand() and rand(). These functions produce random numbers of lesser quality, but for the purpose (a retry time-out) they are still good enough. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jun 5, 2015 at 21:45 UTC 1e9676ec0a771de06abca3009eb4bdc5a4ae3312
1 file changed +2 -2
lockfile.c
+2 -2
@@ -191,7 +191,7 @@ static int lock_file_timeout(struct lock_file *lk, const char *path,
191 return lock_file(lk, path, flags);
192
193 if (!random_initialized) {
194 - srandom((unsigned int)getpid());
194 + srand((unsigned int)getpid());
195 random_initialized = 1;
196 }
197
@@ -218,7 +218,7 @@ static int lock_file_timeout(struct lock_file *lk, const char *path,
218
219 backoff_ms = multiplier * INITIAL_BACKOFF_MS;
220 /* back off for between 0.75*backoff_ms and 1.25*backoff_ms */
221 - wait_us = (750 + random() % 500) * backoff_ms;
221 + wait_us = (750 + rand() % 500) * backoff_ms;
222 sleep_microseconds(wait_us);
223 remaining_us -= wait_us;
224