diff --git a/command.c b/command.c index 11e4667d..ae27ac35 100644 --- a/command.c +++ b/command.c @@ -53,7 +53,7 @@ gboolean process_input(char *inp) if (strlen(inp) == 0) { result = TRUE; } else if (inp[0] == '/') { - inp = trim(inp); + trim(inp); char inp_cpy[strlen(inp) + 1]; strcpy(inp_cpy, inp); char *command = strtok(inp_cpy, " "); diff --git a/test_util.c b/test_util.c index d29a139b..4888f676 100644 --- a/test_util.c +++ b/test_util.c @@ -199,9 +199,9 @@ void trim_when_empty(void) void trim_when_null(void) { char *str = NULL; - trim(str); + char *result = trim(str); - assert_is_null(str); + assert_is_null(result); } void register_util_tests(void) diff --git a/util.c b/util.c index b4c152a4..790c6a24 100644 --- a/util.c +++ b/util.c @@ -25,6 +25,8 @@ #include #include +#include + void get_time(char *thetime) { time_t rawtime; @@ -41,21 +43,7 @@ char *trim(char *str) if (str == NULL) return NULL; - char *end; - - while (isspace(*str)) - str++; - - if (*str == 0) - return str; - - end = str + strlen(str) - 1; - while (end > str && isspace(*end)) - end--; - - *(end+1) = 0; - - return str; + return g_strstrip(str); } char * str_replace (const char *string, const char *substr,