X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fciniparser%2Fciniparser.c;h=527f83776e86428c5e283b76211291445ae7b4f9;hp=1e647c1d051dde5367a89547cb2168fd6baed3a9;hb=HEAD;hpb=28f7279805d3c9378362003031ae537a32d9bec4 diff --git a/ccan/ciniparser/ciniparser.c b/ccan/ciniparser/ciniparser.c index 1e647c1d..527f8377 100644 --- a/ccan/ciniparser/ciniparser.c +++ b/ccan/ciniparser/ciniparser.c @@ -33,7 +33,7 @@ */ #include -#include "ciniparser.h" +#include #define ASCIILINESZ (1024) #define INI_INVALID_KEY ((char*) NULL) @@ -69,16 +69,9 @@ static char *strlwc(const char *s) if (s == NULL) return NULL; - memset(l, 0, ASCIILINESZ+1); - i=0; - - while (s[i] && i < ASCIILINESZ) { - l[i] = (char)tolower((int)s[i]); - i++; - } - - l[ASCIILINESZ] = (char) 0; - + for (i = 0; s[i] && i < ASCIILINESZ; i++) + l[i] = tolower(s[i]); + l[i] = '\0'; return l; } @@ -94,30 +87,26 @@ static char *strlwc(const char *s) * is statically allocated, it will be modified at each function call * (not re-entrant). */ -static char *strstrip(char *s) +static char *strstrip(const char *s) { static char l[ASCIILINESZ+1]; - char *last; + unsigned int i, numspc; if (s == NULL) return NULL; - while (isspace((int)*s) && *s) + while (isspace(*s)) s++; - memset(l, 0, ASCIILINESZ+1); - strcpy(l, s); - last = l + strlen(l); - - while (last > l) { - if (!isspace((int)*(last-1))) - break; - last --; + for (i = numspc = 0; s[i] && i < ASCIILINESZ; i++) { + l[i] = s[i]; + if (isspace(l[i])) + numspc++; + else + numspc = 0; } - - *last = (char) 0; - - return (char *) l; + l[i - numspc] = '\0'; + return l; } /** @@ -139,7 +128,6 @@ line_status ciniparser_line(char *input_line, char *section, strcpy(line, strstrip(input_line)); len = (int) strlen(line); - sta = LINE_UNPROCESSED; if (len < 1) { /* Empty line */ sta = LINE_EMPTY; @@ -328,7 +316,7 @@ int ciniparser_getint(dictionary *d, const char *key, int notfound) return (int) strtol(str, NULL, 10); } -double ciniparser_getdouble(dictionary *d, char *key, double notfound) +double ciniparser_getdouble(dictionary *d, const char *key, double notfound) { char *str; @@ -435,12 +423,10 @@ dictionary *ciniparser_load(const char *ininame) } /* Detect multi-line */ - if (line[len] == '\\') { + if (len >= 0 && line[len] == '\\') { /* Multi-line value */ last = len; continue; - } else { - last = 0; } switch (ciniparser_line(line, section, key, val)) {