X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/f16ad9e7befcbd008c053c992cc05ed925a1ec49..cbfd323c3191336a3c07c24725019cdaf87f0dd6:/src/tools.c diff --git a/src/tools.c b/src/tools.c index 4a3d52b..9231b5e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -5,7 +5,7 @@ * * x3 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 + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -357,6 +357,14 @@ static char irc_tolower[256]; #undef tolower #define tolower(X) irc_tolower[(unsigned char)(X)] +void +irc_strtolower(char *str) { + char *p; + for(p = str;*p;p++) { + *p = tolower(*p); + } +} + int irccasecmp(const char *stra, const char *strb) { while (*stra && (tolower(*stra) == tolower(*strb))) @@ -1111,6 +1119,23 @@ char *mysep(char **sepstr, char *delim) return(retstr); } +/* Mallocing snprintf * + * + * If it overruns size, it will simply be safely truncated. + */ +char * +x3_msnprintf(const int size, const char *format, ...) +{ + va_list ap; + char* buff = calloc(sizeof(char *), size+1); + + va_start(ap, format); + vsnprintf(buff, size, format, ap); + va_end(ap); + buff = realloc(buff, strlen(buff) + 1); + return buff; +} + char *time2str(time_t thetime) { char *buf, *tmp; @@ -1276,3 +1301,16 @@ char *pretty_mask(char *mask) } return make_nick_user_host(retmask, nick, user, host); } + +int str_is_number(const char *str) +{ + char *ptr; + int ret = false; + for(ptr = (char *)str;*ptr;ptr++) { + if((*ptr >= '0' && *ptr <= '9') || *ptr == '-') + ret = true; + else + return false; + } + return ret; +}