]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
*/: Rename type_min() => minof(), type_max() => maxof()
authorAlejandro Colomar <alx@kernel.org>
Thu, 27 Nov 2025 00:10:28 +0000 (01:10 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 9 Jul 2026 20:45:02 +0000 (22:45 +0200)
GCC 16 has added two new operators, _Minof() and _Maxof().
Let's name our macros like these (but without the reserved names).

I'm also working on standardization of these operators within the
C Committee.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3628.txt>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/atoi/a2i.h
lib/atoi/getnum.h
lib/limits.c
lib/typetraits.h
src/usermod.c
tests/unit/test_typetraits.c

index e7ece423adeb7a5f785857bd76d5aa1d1697b6b0..96d468ec40a83c6385b5f632db33847e03d68218 100644 (file)
@@ -53,7 +53,7 @@
 #define a2ul(...)   a2i(unsigned long, __VA_ARGS__)
 #define a2ull(...)  a2i(unsigned long long, __VA_ARGS__)
 
-#define str2i(T, ...)  a2i(T, __VA_ARGS__, NULL, 0, type_min(T), type_max(T))
+#define str2i(T, ...)  a2i(T, __VA_ARGS__, NULL, 0, minof(T), maxof(T))
 
 #define str2sh(...)    str2i(short, __VA_ARGS__)
 #define str2si(...)    str2i(int, __VA_ARGS__)
index e5cb50f4601e6b646bce38d92cb688d1bdbd2c24..e0575523037f30bafe312d72df32fa770528e528 100644 (file)
@@ -38,21 +38,21 @@ get_fd(const char *restrict fdstr, int *restrict fd)
 inline int
 get_gid(const char *restrict gidstr, gid_t *restrict gid)
 {
-       return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
+       return a2i(gid_t, gid, gidstr, NULL, 10, minof(gid_t), maxof(gid_t));
 }
 
 
 inline int
 get_pid(const char *restrict pidstr, pid_t *restrict pid)
 {
-       return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t));
+       return a2i(pid_t, pid, pidstr, NULL, 10, 1, maxof(pid_t));
 }
 
 
 inline int
 get_uid(const char *restrict uidstr, uid_t *restrict uid)
 {
-       return a2i(uid_t, uid, uidstr, NULL, 10, type_min(uid_t), type_max(uid_t));
+       return a2i(uid_t, uid, uidstr, NULL, 10, minof(uid_t), maxof(uid_t));
 }
 
 
index 129a99fd75f1f4a4a12a15652e870081784abb2a..3fabe54d3ad370ee13331e0bac8d919b7e75390f 100644 (file)
@@ -64,7 +64,7 @@ static int setrlimit_value (unsigned int resource,
                limit = RLIM_INFINITY;
 
        } else {
-               if (a2i(rlim_t, &l, value, NULL, 10, 0, type_max(rlim_t)) == -1
+               if (a2i(rlim_t, &l, value, NULL, 10, 0, maxof(rlim_t)) == -1
                    && errno != ENOTSUP)
                {
                        return 0;  // FIXME: we could instead throw an error, though.
index edb1c76d1fddf24489a46b89382c6261b9766660..af952f86be23b412e4136a1b2fb8e8b850bd5498 100644 (file)
@@ -15,8 +15,8 @@
 # define is_signed(x)    ((typeof(x)) -1 < 1)
 # define stype_max(T)    ((T) (((((T) 1 << (WIDTHOF(T) - 2)) - 1) << 1) + 1))
 # define utype_max(T)    ((T) -1)
-# define type_max(T)     ((T) (is_signed(T) ? stype_max(T) : utype_max(T)))
-# define type_min(T)     ((T) ~type_max(T))
+# define maxof(T)        ((T) (is_signed(T) ? stype_max(T) : utype_max(T)))
+# define minof(T)        ((T) ~maxof(T))
 
 
 #define is_same_type(a, b)                                                    \
index d0a6158cf647d9af4cbe2b7a6921f47e4c8d9d00..1bd5b7ccf2d106d041d9878640a050ce82ddb853 100644 (file)
@@ -326,15 +326,15 @@ getid_range(const char *str)
        id_t             first, last;
        const char       *pos;
        struct id_range  result = {
-               .first = type_max(id_t),
-               .last = type_min(id_t)
+               .first = maxof(id_t),
+               .last = minof(id_t)
        };
 
        static_assert(is_same_type(id_t, uid_t), "");
        static_assert(is_same_type(id_t, gid_t), "");
 
-       first = type_min(id_t);
-       last = type_max(id_t);
+       first = minof(id_t);
+       last = maxof(id_t);
 
        if (a2i(id_t, &first, str, &pos, 10, first, last) == -1
            && errno != ENOTSUP)
index f547ec193a16980dfb9998e7217c058f9f2eec2e..ec545b8c5aef0ec982cc82b2fde636a7ee776977 100644 (file)
 #include "typetraits.h"
 #include "attr.h"
 
-static void test_type_max(MAYBE_UNUSED void ** _1);
-static void test_type_min(MAYBE_UNUSED void ** _1);
+
+static void test_maxof(MAYBE_UNUSED void ** _1);
+static void test_minof(MAYBE_UNUSED void ** _1);
 
 
 int
 main(void)
 {
        const struct CMUnitTest  tests[] = {
-               cmocka_unit_test(test_type_max),
-               cmocka_unit_test(test_type_min),
+               cmocka_unit_test(test_maxof),
+               cmocka_unit_test(test_minof),
        };
 
        return cmocka_run_group_tests(tests, NULL, NULL);
@@ -30,26 +31,26 @@ main(void)
 
 
 static void
-test_type_max(MAYBE_UNUSED void ** _1)
+test_maxof(MAYBE_UNUSED void ** _1)
 {
-       assert_true(type_max(long) == LONG_MAX);
-       assert_true(type_max(unsigned long) == ULONG_MAX);
-       assert_true(type_max(int) == INT_MAX);
-       assert_true(type_max(unsigned short) == USHRT_MAX);
-       assert_true(type_max(char) == CHAR_MAX);
-       assert_true(type_max(signed char) == SCHAR_MAX);
-       assert_true(type_max(unsigned char) == UCHAR_MAX);
+       assert_true(maxof(long) == LONG_MAX);
+       assert_true(maxof(unsigned long) == ULONG_MAX);
+       assert_true(maxof(int) == INT_MAX);
+       assert_true(maxof(unsigned short) == USHRT_MAX);
+       assert_true(maxof(char) == CHAR_MAX);
+       assert_true(maxof(signed char) == SCHAR_MAX);
+       assert_true(maxof(unsigned char) == UCHAR_MAX);
 }
 
 
 static void
-test_type_min(MAYBE_UNUSED void ** _1)
+test_minof(MAYBE_UNUSED void ** _1)
 {
-       assert_true(type_min(long) == LONG_MIN);
-       assert_true(type_min(unsigned long) == 0);
-       assert_true(type_min(int) == INT_MIN);
-       assert_true(type_min(unsigned short) == 0);
-       assert_true(type_min(char) == CHAR_MIN);
-       assert_true(type_min(signed char) == SCHAR_MIN);
-       assert_true(type_min(unsigned char) == 0);
+       assert_true(minof(long) == LONG_MIN);
+       assert_true(minof(unsigned long) == 0);
+       assert_true(minof(int) == INT_MIN);
+       assert_true(minof(unsigned short) == 0);
+       assert_true(minof(char) == CHAR_MIN);
+       assert_true(minof(signed char) == SCHAR_MIN);
+       assert_true(minof(unsigned char) == 0);
 }