/*
* 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
* Tool functions
*/
-#include "imp.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <syslog.h>
#endif
-#include "exp.h"
#include "tool.h"
ptr = String;
while(*ptr) {
- *ptr = toupper(*ptr);
+ *ptr = toupper((int)*ptr);
ptr++;
}
return String;
ptr = String;
while(*ptr) {
- *ptr = tolower(*ptr);
+ *ptr = tolower((int)*ptr);
ptr++;
}
return String;
* 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);
+#ifndef HAVE_ARC4RANDOM
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)];
}
-
+#else
+ for (i = 0; i < len; ++i)
+ String[i] = chars[arc4random() % (sizeof(chars) - 1)];
+#endif
String[len] = '\0';
return String;