9 uint64_t *p_val,
ABT_bool *p_overflow);
15 int abt_errno =
atoi_impl(str, &is_signed, &val, &overflow);
16 ABTI_CHECK_ERROR(abt_errno);
18 if (val > (uint64_t)(-(int64_t)INT_MIN)) {
23 *p_val = (int)(-(int64_t)val);
26 if (val > (uint64_t)INT_MAX) {
35 *p_overflow = overflow;
44 int abt_errno =
atoi_impl(str, &is_signed, &val, &overflow);
45 ABTI_CHECK_ERROR(abt_errno);
52 if (val > (uint64_t)UINT32_MAX) {
57 *p_val = (uint32_t)val;
61 *p_overflow = overflow;
70 int abt_errno =
atoi_impl(str, &is_signed, &val, &overflow);
71 ABTI_CHECK_ERROR(abt_errno);
81 *p_overflow = overflow;
88 ABTI_STATIC_ASSERT(
sizeof(
size_t) == 4 ||
sizeof(
size_t) == 8);
89 if (
sizeof(
size_t) == 4) {
93 ABTI_CHECK_ERROR(abt_errno);
96 *p_overflow = overflow;
102 ABTI_CHECK_ERROR(abt_errno);
103 *p_val = (size_t)val;
105 *p_overflow = overflow;
115 uint64_t *p_val,
ABT_bool *p_overflow)
121 if ((*str ==
'\n' || *str ==
'\t' || *str ==
' ' || *str ==
'\r') &&
124 }
else if (*str ==
'+' && read_digit ==
ABT_FALSE) {
126 }
else if (*str ==
'-' && read_digit ==
ABT_FALSE) {
130 }
else if (
'0' <= *str && *str <=
'9') {
134 if ((val > UINT64_MAX / 10) ||
135 (val * 10 > UINT64_MAX - (uint64_t)(*str -
'0'))) {
139 *p_is_signed = is_signed;
142 val = val * 10 + (uint64_t)(*str -
'0');
152 *p_is_signed = is_signed;
161 void test_ABTU_atoi(
const char *str,
int err,
int val,
ABT_bool overflow)
165 int ret_err =
ABTU_atoi(str, &ret_val, &ret_overflow);
166 assert(err == ret_err);
168 assert(val == ret_val);
169 assert(overflow == ret_overflow);
173 void test_ABTU_atoui32(
const char *str,
int err, uint32_t val,
ABT_bool overflow)
177 int ret_err =
ABTU_atoui32(str, &ret_val, &ret_overflow);
178 assert(err == ret_err);
180 assert(val == ret_val);
181 assert(overflow == ret_overflow);
185 void test_ABTU_atoui64(
const char *str,
int err, uint64_t val,
ABT_bool overflow)
189 int ret_err =
ABTU_atoui64(str, &ret_val, &ret_overflow);
190 assert(err == ret_err);
192 assert(val == ret_val);
193 assert(overflow == ret_overflow);
197 void test_ABTU_atosz(
const char *str,
int err,
size_t val,
ABT_bool overflow)
201 int ret_err =
ABTU_atosz(str, &ret_val, &ret_overflow);
202 assert(err == ret_err);
204 assert(val == ret_val);
205 assert(overflow == ret_overflow);
218 base_case_t cases[] = {
243 for (i = 0; i <
sizeof(cases) /
sizeof(cases[0]); i++) {
244 test_ABTU_atoi(cases[i].str, cases[i].err, cases[i].val,
ABT_FALSE);
245 test_ABTU_atoui32(cases[i].str, cases[i].err, cases[i].val,
ABT_FALSE);
246 test_ABTU_atoui64(cases[i].str, cases[i].err, cases[i].val,
ABT_FALSE);
247 test_ABTU_atosz(cases[i].str, cases[i].err, cases[i].val,
ABT_FALSE);
272 test_ABTU_atoui64(
"18446744073709551614",
ABT_SUCCESS,
274 test_ABTU_atoui64(
"18446744073709551615",
ABT_SUCCESS,
276 test_ABTU_atoui64(
"18446744073709551616",
ABT_SUCCESS,
278 test_ABTU_atoui64(
"111118446744073709551615",
ABT_SUCCESS,
283 if (
sizeof(
size_t) == 4) {
291 assert(
sizeof(
size_t) == 8);
292 test_ABTU_atosz(
"18446744073709551614",
ABT_SUCCESS,
294 test_ABTU_atosz(
"18446744073709551615",
ABT_SUCCESS,
296 test_ABTU_atosz(
"18446744073709551616",
ABT_SUCCESS,
298 test_ABTU_atosz(
"111118446744073709551615",
ABT_SUCCESS,