return fwd;
}
+static const char quote_marker[] = { '\0', '"', '\0' };
+bool is_quote(const char* token)
+{
+ return !memcmp(token, quote_marker, sizeof(quote_marker));
+}
+
vector
alloc_strvec(char *string)
{
start = cp;
if (*cp == '"' && !(in_string && *(cp + 1) == '"')) {
cp++;
- token = MALLOC(2);
+ token = MALLOC(sizeof(quote_marker));
if (!token)
goto out;
- *(token) = '"';
- *(token + 1) = '\0';
+ memcpy(token, quote_marker, sizeof(quote_marker));
if (in_string)
in_string = 0;
else
(char *)VECTOR_SLOT(strvec, 0));
return NULL;
}
- size = strlen(str);
- if (size == 0) {
- condlog(0, "option '%s' has empty value",
- (char *)VECTOR_SLOT(strvec, 0));
- return NULL;
- }
- if (*str != '"') {
+ if (!is_quote(str)) {
+ size = strlen(str);
+ if (size == 0) {
+ condlog(0, "option '%s' has empty value",
+ (char *)VECTOR_SLOT(strvec, 0));
+ return NULL;
+ }
alloc = MALLOC(sizeof (char) * (size + 1));
if (alloc)
memcpy(alloc, str, size);
(char *)VECTOR_SLOT(strvec, 0));
return NULL;
}
- if (*str == '"')
+ if (is_quote(str))
break;
tmp = alloc;
/* The first +1 is for the NULL byte. The rest are for the
(char *)VECTOR_SLOT(strvec, 0), line_nr, file);
return -1;
}
- if (*str != '"') {
+ if (!is_quote(str)) {
if (VECTOR_SIZE(strvec) > 2)
condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, 2), line_nr, file);
return 0;
line_nr, file);
return -1;
}
- if (*str == '"') {
+ if (is_quote(str)) {
if (VECTOR_SIZE(strvec) > i + 1)
condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, (i + 1)), line_nr, file);
return 0;