From: Alejandro Colomar Date: Thu, 27 Nov 2025 00:10:28 +0000 (+0100) Subject: */: Rename type_min() => minof(), type_max() => maxof() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4f2c7d8139230c1f604d90a93e8b69d00f07c73;p=thirdparty%2Fshadow.git */: Rename type_min() => minof(), type_max() => maxof() 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: Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/atoi/a2i.h b/lib/atoi/a2i.h index e7ece423a..96d468ec4 100644 --- a/lib/atoi/a2i.h +++ b/lib/atoi/a2i.h @@ -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__) diff --git a/lib/atoi/getnum.h b/lib/atoi/getnum.h index e5cb50f46..e05755230 100644 --- a/lib/atoi/getnum.h +++ b/lib/atoi/getnum.h @@ -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)); } diff --git a/lib/limits.c b/lib/limits.c index 129a99fd7..3fabe54d3 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -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. diff --git a/lib/typetraits.h b/lib/typetraits.h index edb1c76d1..af952f86b 100644 --- a/lib/typetraits.h +++ b/lib/typetraits.h @@ -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) \ diff --git a/src/usermod.c b/src/usermod.c index d0a6158cf..1bd5b7ccf 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -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) diff --git a/tests/unit/test_typetraits.c b/tests/unit/test_typetraits.c index f547ec193..ec545b8c5 100644 --- a/tests/unit/test_typetraits.c +++ b/tests/unit/test_typetraits.c @@ -13,16 +13,17 @@ #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); }