mirror of
https://github.com/systemd/systemd
synced 2024-09-06 08:46:19 +00:00
conf-parser: minor optimization in config_parse_string()
This commit is contained in:
parent
3b43629240
commit
8f2665a463
|
@ -565,57 +565,55 @@ int config_parse_bool(const char* unit,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_string(const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
int config_parse_string(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
char **s = data;
|
||||
char *n;
|
||||
char **s = data, *n;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
n = strdup(rvalue);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
|
||||
if (!utf8_is_valid(n)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
||||
"String is not UTF-8 clean, ignoring assignment: %s", rvalue);
|
||||
free(n);
|
||||
if (!utf8_is_valid(rvalue)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "String is not UTF-8 clean, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(*s);
|
||||
if (*n)
|
||||
*s = n;
|
||||
if (isempty(rvalue))
|
||||
n = NULL;
|
||||
else {
|
||||
free(n);
|
||||
*s = NULL;
|
||||
n = strdup(rvalue);
|
||||
if (!n)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
free(*s);
|
||||
*s = n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_path(const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
int config_parse_path(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
char **s = data, *n;
|
||||
|
||||
|
|
Loading…
Reference in a new issue