From 5806784b5c7618d2a0407effe013b8734ce6917d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 17 Mar 2015 22:29:31 -0400 Subject: [PATCH] bootctl: modernization Use strjoina to avoid error handling, and openat to simplify things. Some fixes on the way: - ferror does not set errno, so the return value was wrong in some cases - errors are propagated in more cases - EFI/systemd was created, but EFI/systemd-boot was deleted - something is always printed on error - when checking the version, comparison was done against "systemd-bo" for some reason - return value was converted from negative to EXIT_SUCCESS/EXIT_FAILURE twice, resulting in EXIT_SUCCESS all the time --- src/shared/util.c | 21 +++++++++++++++++++++ src/shared/util.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index 72984735c..392c42ba2 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -151,6 +151,27 @@ char* endswith(const char *s, const char *postfix) { return (char*) s + sl - pl; } +char* endswith_no_case(const char *s, const char *postfix) { + size_t sl, pl; + + assert(s); + assert(postfix); + + sl = strlen(s); + pl = strlen(postfix); + + if (pl == 0) + return (char*) s + sl; + + if (sl < pl) + return NULL; + + if (strcasecmp(s + sl - pl, postfix) != 0) + return NULL; + + return (char*) s + sl - pl; +} + char* first_word(const char *s, const char *word) { size_t sl, wl; const char *p; diff --git a/src/shared/util.h b/src/shared/util.h index 11cc10ba3..3b3a05643 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -183,6 +183,7 @@ static inline char *startswith_no_case(const char *s, const char *prefix) { } char *endswith(const char *s, const char *postfix) _pure_; +char *endswith_no_case(const char *s, const char *postfix) _pure_; char *first_word(const char *s, const char *word) _pure_; -- 2.30.2