summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-17 22:29:31 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-05-19 23:41:38 -0400
commitd3226d7796b44cb758b1a59db608a73bd0d9b802 (patch)
treefde8db14c3f00d5b7563dc278ddf1982c4dbcd25 /src/shared
parent7f4e6a1cebe6d2da38b52b535f3e05b7a778c6bc (diff)
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
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c21
-rw-r--r--src/shared/util.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index fd837d96bd..e18645f8f1 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -148,6 +148,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 a2b1ec5030..0e806cf1a1 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -134,6 +134,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_;