chiark / gitweb /
bootctl: move toupper() implementation to string-util.h
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Jul 2016 18:43:54 +0000 (20:43 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 5 Jul 2017 06:50:49 +0000 (08:50 +0200)
We already have tolower() calls there, hence let's unify this at one place.
Also, update the code to only use ASCII operations, so that we don't end up
being locale dependant.

src/basic/string-util.c
src/basic/string-util.h

index 293a15f9c041cf59f5354829cfdc86b0b0622a20..e9856b90d39215ac3e6e952f0966a362f8c5b5a1 100644 (file)
@@ -323,6 +323,14 @@ char ascii_tolower(char x) {
         return x;
 }
 
         return x;
 }
 
+char ascii_toupper(char x) {
+
+        if (x >= 'a' && x <= 'z')
+                return x - 'a' + 'A';
+
+        return x;
+}
+
 char *ascii_strlower(char *t) {
         char *p;
 
 char *ascii_strlower(char *t) {
         char *p;
 
@@ -334,6 +342,17 @@ char *ascii_strlower(char *t) {
         return t;
 }
 
         return t;
 }
 
+char *ascii_strupper(char *t) {
+        char *p;
+
+        assert(t);
+
+        for (p = t; *p; p++)
+                *p = ascii_toupper(*p);
+
+        return t;
+}
+
 char *ascii_strlower_n(char *t, size_t n) {
         size_t i;
 
 char *ascii_strlower_n(char *t, size_t n) {
         size_t i;
 
index 1209e1e2e14c11853b526891d31b34584c36db68..b75aba63c29d4b8ef0341899f5732f5b6d63f694 100644 (file)
@@ -137,6 +137,9 @@ char ascii_tolower(char x);
 char *ascii_strlower(char *s);
 char *ascii_strlower_n(char *s, size_t n);
 
 char *ascii_strlower(char *s);
 char *ascii_strlower_n(char *s, size_t n);
 
+char ascii_toupper(char x);
+char *ascii_strupper(char *s);
+
 int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
 int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);
 
 int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
 int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);