1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

Merge pull request #14617 from poettering/no-strv-clear

strv: remove strv_clear() and some other minor fixes
This commit is contained in:
Lennart Poettering 2020-01-21 15:08:38 +01:00 committed by GitHub
commit c680e4efa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 35 deletions

View File

@ -57,20 +57,15 @@ char *strv_find_startswith(char * const *l, const char *name) {
return NULL; return NULL;
} }
void strv_clear(char **l) { char **strv_free(char **l) {
char **k; char **k;
if (!l) if (!l)
return; return NULL;
for (k = l; *k; k++) for (k = l; *k; k++)
free(*k); free(*k);
*l = NULL;
}
char **strv_free(char **l) {
strv_clear(l);
return mfree(l); return mfree(l);
} }

View File

@ -25,8 +25,6 @@ char **strv_free_erase(char **l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase); DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase);
#define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep) #define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep)
void strv_clear(char **l);
char **strv_copy(char * const *l); char **strv_copy(char * const *l);
size_t strv_length(char * const *l) _pure_; size_t strv_length(char * const *l) _pure_;

View File

@ -446,7 +446,7 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c
value = strchr(line, '='); value = strchr(line, '=');
if (!value) if (!value)
return log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
"Key-value pair expected but got \"%s\", ignoring", line); "Key-value pair expected but got \"%s\", ignoring", line);
value[0] = '\0'; value[0] = '\0';
@ -457,7 +457,7 @@ static int insert_data(struct trie *trie, char **match_list, char *line, const c
line++; line++;
if (isempty(line + 1) || isempty(value)) if (isempty(line + 1) || isempty(value))
return log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, return log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
"Empty %s in \"%s=%s\", ignoring", "Empty %s in \"%s=%s\", ignoring",
isempty(line + 1) ? "key" : "value", isempty(line + 1) ? "key" : "value",
line, value); line, value);
@ -477,7 +477,6 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **match_list = NULL; _cleanup_strv_free_ char **match_list = NULL;
uint32_t line_number = 0; uint32_t line_number = 0;
char *match = NULL;
int r = 0, err; int r = 0, err;
f = fopen(filename, "re"); f = fopen(filename, "re");
@ -518,20 +517,15 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
break; break;
if (line[0] == ' ') { if (line[0] == ' ') {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
"Match expected but got indented property \"%s\", ignoring line", line); "Match expected but got indented property \"%s\", ignoring line", line);
r = -EINVAL;
break; break;
} }
/* start of record, first match */ /* start of record, first match */
state = HW_MATCH; state = HW_MATCH;
match = strdup(line); err = strv_extend(&match_list, line);
if (!match)
return -ENOMEM;
err = strv_consume(&match_list, match);
if (err < 0) if (err < 0)
return err; return err;
@ -539,21 +533,16 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
case HW_MATCH: case HW_MATCH:
if (len == 0) { if (len == 0) {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
"Property expected, ignoring record with no properties"); "Property expected, ignoring record with no properties");
r = -EINVAL;
state = HW_NONE; state = HW_NONE;
strv_clear(match_list); match_list = strv_free(match_list);
break; break;
} }
if (line[0] != ' ') { if (line[0] != ' ') {
/* another match */ /* another match */
match = strdup(line); err = strv_extend(&match_list, line);
if (!match)
return -ENOMEM;
err = strv_consume(&match_list, match);
if (err < 0) if (err < 0)
return err; return err;
@ -571,16 +560,15 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
if (len == 0) { if (len == 0) {
/* end of record */ /* end of record */
state = HW_NONE; state = HW_NONE;
strv_clear(match_list); match_list = strv_free(match_list);
break; break;
} }
if (line[0] != ' ') { if (line[0] != ' ') {
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, r = log_syntax(NULL, LOG_WARNING, filename, line_number, SYNTHETIC_ERRNO(EINVAL),
"Property or empty line expected, got \"%s\", ignoring record", line); "Property or empty line expected, got \"%s\", ignoring record", line);
r = -EINVAL;
state = HW_NONE; state = HW_NONE;
strv_clear(match_list); match_list = strv_free(match_list);
break; break;
} }
@ -592,7 +580,7 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
} }
if (state == HW_MATCH) if (state == HW_MATCH)
log_syntax(NULL, LOG_WARNING, filename, line_number, EINVAL, log_syntax(NULL, LOG_WARNING, filename, line_number, 0,
"Property expected, ignoring record with no properties"); "Property expected, ignoring record with no properties");
return r; return r;