commit 74be9040183c113d5cb62ad25782099479a5c450 from: Alexander Barton date: Mon Aug 27 20:42:52 2012 UTC ngt_RandomStr(): : make it buildable with pre-ANSI C compilers commit - 298cd9a327dca9717ff352d78f964dd49ca5f9f4 commit + 74be9040183c113d5cb62ad25782099479a5c450 blob - df10918893348a4a1ef4205938e00db49eddb6b7 blob + eb6c131e428462e81d3aad67075c721b429edd00 --- src/tool/tool.c +++ src/tool/tool.c @@ -135,24 +135,20 @@ ngt_TrimLastChr( char *String, const char Chr) * Fill a String with random chars */ GLOBAL char * -ngt_RandomStr( char *String, const size_t len) +ngt_RandomStr(char *String, const size_t len) { + static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`"; + struct timeval t; + size_t i; + assert(String != NULL); - static const char chars[] = - "0123456789ABCDEFGHIJKLMNO" - "PQRSTUVWXYZabcdefghijklmn" - "opqrstuvwxyz!\"#$&'()*+,-" - "./:;<=>?@[\\]^_`"; - - struct timeval t; gettimeofday(&t, NULL); srand((unsigned)(t.tv_usec * t.tv_sec)); - for (size_t i = 0; i < len; ++i) { + for (i = 0; i < len; ++i) { String[i] = chars[rand() % (sizeof(chars) - 1)]; } - String[len] = '\0'; return String;