extern inline unsigned long strtoul_noneg(const char *s,
char **restrict endp, int base);
-extern inline unsigned long long strtoull_noneg(const char *s,
- char **restrict endp, int base);
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline unsigned long strtoul_noneg(const char *s,
char **restrict endp, int base);
-ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
-inline unsigned long long strtoull_noneg(const char *s,
- char **restrict endp, int base);
inline uintmax_t
}
-inline unsigned long long
-strtoull_noneg(const char *s, char **restrict endp, int base)
-{
- if (strtol(s, endp, base) < 0) {
- errno = ERANGE;
- return 0;
- }
- return strtoull(s, endp, base);
-}
-
-
#endif // include guard
static void test_strtoul_noneg(void **state);
-static void test_strtoull_noneg(void **state);
int
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_strtoul_noneg),
- cmocka_unit_test(test_strtoull_noneg),
};
return cmocka_run_group_tests(tests, NULL, NULL);
assert_true(strtoul_noneg("-0x10000000000000000", NULL, 0) == 0);
assert_true(errno == ERANGE);
}
-
-
-static void
-test_strtoull_noneg(void **state)
-{
- errno = 0;
- assert_true(strtoull_noneg("42", NULL, 0) == 42);
- assert_true(errno == 0);
-
- assert_true(strtoull_noneg("-1", NULL, 0) == 0);
- assert_true(errno == ERANGE);
- errno = 0;
- assert_true(strtoull_noneg("-3", NULL, 0) == 0);
- assert_true(errno == ERANGE);
- errno = 0;
- assert_true(strtoull_noneg("-0xFFFFFFFFFFFFFFFF", NULL, 0) == 0);
- assert_true(errno == ERANGE);
-
- errno = 0;
- assert_true(strtoull_noneg("-0x10000000000000000", NULL, 0) == 0);
- assert_true(errno == ERANGE);
-}