diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-11-07 01:19:48 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-07 01:19:56 +0100 |
commit | f4934dfaaac70c6d0d49463af62cbd089bfa64c8 (patch) | |
tree | e5d62205d2902087c088d9fad0d797111dcac486 | |
parent | b5e1fad5b1b9d29694e8c51245821a732fc22f93 (diff) |
util: simplify normalize_env_assignment() a bit
-rw-r--r-- | src/shared/util.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 3eb8a0f442..3411cea343 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2783,7 +2783,7 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) { if (k < 0) return k; - snprintf(fn, sizeof(fn), "/dev/char/%u:%u", major(devnr), minor(devnr)); + sprintf(fn, "/dev/char/%u:%u", major(devnr), minor(devnr)); k = readlink_malloc(fn, &s); if (k < 0) { @@ -3591,41 +3591,33 @@ char *unquote(const char *s, const char* quotes) { } char *normalize_env_assignment(const char *s) { - _cleanup_free_ char *name = NULL, *value = NULL, *p = NULL; - char *eq, *r; + _cleanup_free_ char *value = NULL; + const char *eq; + char *p, *name; eq = strchr(s, '='); if (!eq) { - char *t; + char *r, *t; r = strdup(s); if (!r) return NULL; t = strstrip(r); - if (t == r) - return r; + if (t != r) + memmove(r, t, strlen(t) + 1); - memmove(r, t, strlen(t) + 1); return r; } - name = strndup(s, eq - s); - if (!name) - return NULL; - - p = strdup(eq + 1); - if (!p) - return NULL; + name = strndupa(s, eq - s); + p = strdupa(eq + 1); value = unquote(strstrip(p), QUOTES); if (!value) return NULL; - if (asprintf(&r, "%s=%s", strstrip(name), value) < 0) - r = NULL; - - return r; + return strjoin(strstrip(name), "=", value, NULL); } int wait_for_terminate(pid_t pid, siginfo_t *status) { |