win32: Fix random file name generation, init random generator once.

This commit is contained in:
Klaas Freitag 2012-06-20 10:40:40 +02:00
parent dd2e9ba747
commit 92ec13d886
2 changed files with 10 additions and 2 deletions

View file

@ -353,6 +353,9 @@ retry_vio_init:
ctx->status = CSYNC_STATUS_INIT;
/* initialize random generator */
srand(time(NULL));
rc = 0;
out:

View file

@ -132,10 +132,15 @@ int c_tmpname(char *template) {
}
}
srand(time(NULL));
for (i = 0; i < 6; ++i) {
#ifdef _WIN32
/* in win32 MAX_RAND is 32767, thus we can not shift that far,
* otherwise the last three chars are 0
*/
int hexdigit = (rand() >> (i * 2)) & 0x1f;
#else
int hexdigit = (rand() >> (i * 5)) & 0x1f;
#endif
tmp[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
}