diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-01-10 17:11:19 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-01-10 17:11:19 +0100 |
commit | ad5d4b1703da43acfa69503c7101cb754066914c (patch) | |
tree | 388056ecd6fee91df32f328f0f6197b767fe9815 /src/basic | |
parent | 4631116dd99f11fbeebecf454e6f62a8f100e411 (diff) | |
download | systemd-ad5d4b1703da43acfa69503c7101cb754066914c.tar.gz systemd-ad5d4b1703da43acfa69503c7101cb754066914c.tar.bz2 systemd-ad5d4b1703da43acfa69503c7101cb754066914c.zip |
cocci: use strempty() at more places
This shortens the code by a few lines.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/fileio.c | 9 | ||||
-rw-r--r-- | src/basic/string-util.h | 6 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 430851cc8c..26d6174664 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1225,8 +1225,7 @@ int tempfn_xxxxxx(const char *p, const char *extra, char **ret) { if (!filename_is_valid(fn)) return -EINVAL; - if (!extra) - extra = ""; + extra = strempty(extra); t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1); if (!t) @@ -1259,8 +1258,7 @@ int tempfn_random(const char *p, const char *extra, char **ret) { if (!filename_is_valid(fn)) return -EINVAL; - if (!extra) - extra = ""; + extra = strempty(extra); t = new(char, strlen(p) + 2 + strlen(extra) + 16 + 1); if (!t) @@ -1300,8 +1298,7 @@ int tempfn_random_child(const char *p, const char *extra, char **ret) { return r; } - if (!extra) - extra = ""; + extra = strempty(extra); t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1); if (!t) diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 09a737ad37..d8f97e697b 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -52,15 +52,15 @@ static inline bool streq_ptr(const char *a, const char *b) { } static inline const char* strempty(const char *s) { - return s ? s : ""; + return s ?: ""; } static inline const char* strnull(const char *s) { - return s ? s : "(null)"; + return s ?: "(null)"; } static inline const char *strna(const char *s) { - return s ? s : "n/a"; + return s ?: "n/a"; } static inline bool isempty(const char *p) { |