diff options
| author | Alexander Barton <alex@barton.de> | 2012-08-27 22:42:52 +0200 |
|---|---|---|
| committer | Alexander Barton <alex@barton.de> | 2012-08-27 22:42:52 +0200 |
| commit | 74be9040183c113d5cb62ad25782099479a5c450 (patch) | |
| tree | a1b9b1bdcadfd46012c3d6a493204a972e3a069d /src/tool/tool.c | |
| parent | 298cd9a327dca9717ff352d78f964dd49ca5f9f4 (diff) | |
| download | ngircd-74be9040183c113d5cb62ad25782099479a5c450.tar.gz ngircd-74be9040183c113d5cb62ad25782099479a5c450.zip | |
ngt_RandomStr(): : make it buildable with pre-ANSI C compilers
Diffstat (limited to 'src/tool/tool.c')
| -rw-r--r-- | src/tool/tool.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/tool/tool.c b/src/tool/tool.c index df109188..eb6c131e 100644 --- a/src/tool/tool.c +++ b/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) { - assert(String != NULL); + static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`"; + struct timeval t; + size_t i; - static const char chars[] = - "0123456789ABCDEFGHIJKLMNO" - "PQRSTUVWXYZabcdefghijklmn" - "opqrstuvwxyz!\"#$&'()*+,-" - "./:;<=>?@[\\]^_`"; + assert(String != NULL); - 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; |