X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Ftool%2Ftool.c;h=b00e235eb739039f8d6d66a519689cb7d299308e;hp=dbdb49a2d9904d97d1fe7369c95b56780ac6da8d;hb=7d7eb735f0c8b541e7809a68cb49174605147904;hpb=596bc096b02ef94efe3d73bb747c6ab0368f63bf diff --git a/src/tool/tool.c b/src/tool/tool.c index dbdb49a2..b00e235e 100644 --- a/src/tool/tool.c +++ b/src/tool/tool.c @@ -1,24 +1,27 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001-2010 Alexander Barton (alex@barton.de) + * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * 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" -#include "imp.h" +/** + * @file + * Tool functions + */ + #include #include #include +#include #include +#include #include @@ -27,7 +30,6 @@ #include #endif -#include "exp.h" #include "tool.h" @@ -80,7 +82,7 @@ ngt_UpperStr(char *String) ptr = String; while(*ptr) { - *ptr = toupper(*ptr); + *ptr = toupper((int)*ptr); ptr++; } return String; @@ -99,7 +101,7 @@ ngt_LowerStr(char *String) ptr = String; while(*ptr) { - *ptr = tolower(*ptr); + *ptr = tolower((int)*ptr); ptr++; } return String; @@ -127,6 +129,35 @@ 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); +#ifndef HAVE_ARC4RANDOM + srand((unsigned)(t.tv_usec * t.tv_sec)); + + for (i = 0; i < len; ++i) { + String[i] = chars[rand() % (sizeof(chars) - 1)]; + } +#else + for (i = 0; i < len; ++i) + String[i] = chars[arc4random() % (sizeof(chars) - 1)]; +#endif + String[len] = '\0'; + + return String; +} /* ngt_RandomStr */ + + #ifdef SYSLOG