]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: use IN_SET() more
authorLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2023 12:16:19 +0000 (13:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2023 16:40:45 +0000 (17:40 +0100)
src/basic/time-util.c

index d5c10571c9b169be9a667e2d69911572edde0359..197c4855524972c716361a4e9345991f02d84476 100644 (file)
@@ -308,30 +308,17 @@ char *format_timestamp_style(
         };
 
         struct tm tm;
+        bool utc, us;
         time_t sec;
         size_t n;
-        bool utc = false, us = false;
         int r;
 
         assert(buf);
+        assert(style >= 0);
+        assert(style < _TIMESTAMP_STYLE_MAX);
 
-        switch (style) {
-                case TIMESTAMP_PRETTY:
-                case TIMESTAMP_UNIX:
-                        break;
-                case TIMESTAMP_US:
-                        us = true;
-                        break;
-                case TIMESTAMP_UTC:
-                        utc = true;
-                        break;
-                case TIMESTAMP_US_UTC:
-                        us = true;
-                        utc = true;
-                        break;
-                default:
-                        return NULL;
-        }
+        utc = IN_SET(style, TIMESTAMP_UTC, TIMESTAMP_US_UTC);
+        us = IN_SET(style, TIMESTAMP_US, TIMESTAMP_US_UTC);
 
         if (l < (size_t) (3 +                  /* week day */
                           1 + 10 +             /* space and date */