From: Zbigniew Jędrzejewski-Szmek Date: Wed, 18 Mar 2015 02:29:31 +0000 (-0400) Subject: bootctl: modernization X-Git-Tag: v226.4~1^2~535 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5806784b5c7618d2a0407effe013b8734ce6917d;p=elogind.git 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 --- 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_;