1 | // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s |
2 | |
3 | #include <inttypes.h> |
4 | #include <stdio.h> |
5 | |
6 | void test_strtoi(const char *nptr, int base, intmax_t lo, intmax_t hi) { |
7 | char *p; |
8 | int status; |
9 | intmax_t i = strtoi(nptr, &p, base, lo, hi, &status); |
10 | printf(format: "strtoi: conversion of '%s' to a number %s, using %jd, p=%#" PRIx8 |
11 | "\n" , |
12 | nptr, status ? "failed" : "successful" , i, *p); |
13 | } |
14 | |
15 | void test_strtou(const char *nptr, int base, intmax_t lo, intmax_t hi) { |
16 | char *p; |
17 | int status; |
18 | uintmax_t i = strtou(nptr, &p, base, lo, hi, &status); |
19 | printf(format: "strtou: conversion of '%s' to a number %s, using %ju, p=%#" PRIx8 |
20 | "\n" , |
21 | nptr, status ? "failed" : "successful" , i, *p); |
22 | } |
23 | |
24 | int main(void) { |
25 | printf(format: "strtoi\n" ); |
26 | |
27 | test_strtoi(nptr: "100" , base: 0, lo: 1, hi: 100); |
28 | test_strtoi(nptr: "100" , base: 0, lo: 1, hi: 10); |
29 | test_strtoi(nptr: "100xyz" , base: 0, lo: 1, hi: 100); |
30 | test_strtou(nptr: "100" , base: 0, lo: 1, hi: 100); |
31 | test_strtou(nptr: "100" , base: 0, lo: 1, hi: 10); |
32 | test_strtou(nptr: "100xyz" , base: 0, lo: 1, hi: 100); |
33 | |
34 | // CHECK: strtoi |
35 | // CHECK: strtoi: conversion of '100' to a number successful, using 100, p=0 |
36 | // CHECK: strtoi: conversion of '100' to a number failed, using 10, p=0 |
37 | // CHECK: strtoi: conversion of '100xyz' to a number failed, using 100, p=0x78 |
38 | // CHECK: strtou: conversion of '100' to a number successful, using 100, p=0 |
39 | // CHECK: strtou: conversion of '100' to a number failed, using 10, p=0 |
40 | // CHECK: strtou: conversion of '100xyz' to a number failed, using 100, p=0x78 |
41 | |
42 | return 0; |
43 | } |
44 | |