diff --git a/src/config.c b/src/config.c index ab97857da8abfd19ef09148bb307941c2e7d1615..e6a40e7a3d353cf8cd6de81d8d10c8a7c5300961 100644 --- a/src/config.c +++ b/src/config.c @@ -135,19 +135,19 @@ int load_config(struct vpn_config *cfg, const char *filename) val = equals + 1; // Remove heading spaces - while (key[0] != '\0' && (key[0] == ' ' || key[0] == '\t')) + while (iswhitespace_like(key[0])) key++; - while (val[0] != '\0' && (val[0] == ' ' || val[0] == '\t')) + while (iswhitespace_like(val[0])) val++; // Remove trailing spaces for (i = strlen(key) - 1; i > 0; i--) { - if (key[i] == ' ' || key[i] == '\t') + if (iswhitespace_like(key[i])) key[i] = '\0'; else break; } for (i = strlen(val) - 1; i > 0; i--) { - if (val[i] == ' ' || val[i] == '\t') + if (iswhitespace_like(val[i])) val[i] = '\0'; else break; diff --git a/src/config.h b/src/config.h index b0fae8336b5ee965f4f13db6ff0bb0caa17d6b74..ab0eedb7fc6c4bb250ad69504e5e80918183475a 100644 --- a/src/config.h +++ b/src/config.h @@ -91,4 +91,10 @@ int strtob(const char *str); int load_config(struct vpn_config *cfg, const char *filename); +inline int iswhitespace_like(const char character) +{ + return (character != '\0' \ + && (character == ' ' || character == '\t' || character == '\r')); +} + #endif