X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ftool%2Ftool.c;h=eb6c131e428462e81d3aad67075c721b429edd00;hb=039a939cb8a85f242a017cb4c68003af2b02dfca;hp=dbdb49a2d9904d97d1fe7369c95b56780ac6da8d;hpb=596bc096b02ef94efe3d73bb747c6ab0368f63bf;p=ngircd-alex.git diff --git a/src/tool/tool.c b/src/tool/tool.c index dbdb49a2..eb6c131e 100644 --- a/src/tool/tool.c +++ b/src/tool/tool.c @@ -7,18 +7,22 @@ * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. - * - * Tool functions */ - #include "portab.h" +/** + * @file + * Tool functions + */ + #include "imp.h" #include #include #include +#include #include +#include #include @@ -127,6 +131,30 @@ ngt_TrimLastChr( char *String, const char Chr) } /* ngt_TrimLastChr */ +/** + * Fill a String with random chars + */ +GLOBAL char * +ngt_RandomStr(char *String, const size_t len) +{ + static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`"; + struct timeval t; + size_t i; + + assert(String != NULL); + + gettimeofday(&t, NULL); + srand((unsigned)(t.tv_usec * t.tv_sec)); + + for (i = 0; i < len; ++i) { + String[i] = chars[rand() % (sizeof(chars) - 1)]; + } + String[len] = '\0'; + + return String; +} /* ngt_RandomStr */ + + #ifdef SYSLOG