]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale-util: make SpecialGlyph more like our usual enums
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Apr 2021 20:59:43 +0000 (22:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Apr 2021 21:00:43 +0000 (23:00 +0200)
Let's define both an enum and a typedef named SpecialGlyph, the way we
usually do it.

Also, introduce an "invalid" special glyph, assigned to -EINVAL, also
like we always do it. (And handle it somewhat sanely in special_glyph()

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

index 93261e675e2ff4009c3569af30027db001341f7d..b818078158bd2af87b4883f3a1c88989d8046121 100644 (file)
@@ -427,8 +427,10 @@ const char *special_glyph(SpecialGlyph code) {
                 },
         };
 
-        assert(code < _SPECIAL_GLYPH_MAX);
+        if (code < 0)
+                return NULL;
 
+        assert(code < _SPECIAL_GLYPH_MAX);
         return draw_table[code >= _SPECIAL_GLYPH_FIRST_EMOJI ? emoji_enabled() : is_locale_utf8()][code];
 }
 
index 558c5a898bb5c9f7ae659f9d9993639c8d53c5f9..df259d1bbd9f169907e45382d0800dca67a3d6eb 100644 (file)
@@ -39,7 +39,7 @@ void init_gettext(void);
 
 bool is_locale_utf8(void);
 
-typedef enum {
+typedef enum SpecialGlyph {
         SPECIAL_GLYPH_TREE_VERTICAL,
         SPECIAL_GLYPH_TREE_BRANCH,
         SPECIAL_GLYPH_TREE_RIGHT,
@@ -70,6 +70,7 @@ typedef enum {
         SPECIAL_GLYPH_LOCK_AND_KEY,
         SPECIAL_GLYPH_TOUCH,
         _SPECIAL_GLYPH_MAX,
+        _SPECIAL_GLYPH_INVALID = -EINVAL,
 } SpecialGlyph;
 
 const char *special_glyph(SpecialGlyph code) _const_;