1// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2//
3// UNSUPPORTED: darwin, target={{.*(linux|solaris).*}}
4
5#define _OPENBSD_SOURCE
6
7#include <assert.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11int main(void) {
12 const char *errstr;
13
14 printf(format: "strtonum\n");
15
16 long long l = strtonum("100", 1, 100, &errstr);
17 assert(!errstr);
18 printf(format: "%lld\n", l);
19
20 l = strtonum("200", 1, 100, &errstr);
21 assert(errstr);
22 printf(format: "%s\n", errstr);
23
24 l = strtonum("300", 1000, 1001, &errstr);
25 assert(errstr);
26 printf(format: "%s\n", errstr);
27
28 l = strtonum("abc", 1000, 1001, &errstr);
29 assert(errstr);
30 printf(format: "%s\n", errstr);
31
32 l = strtonum("1000", 1001, 1000, &errstr);
33 assert(errstr);
34 printf(format: "%s\n", errstr);
35
36 l = strtonum("1000abc", 1000, 1001, &errstr);
37 assert(errstr);
38 printf(format: "%s\n", errstr);
39
40 l = strtonum("1000.0", 1000, 1001, &errstr);
41 assert(errstr);
42 printf(format: "%s\n", errstr);
43
44 // CHECK: strtonum
45 // CHECK: 100
46 // CHECK: too large
47 // CHECK: too small
48 // CHECK: invalid
49 // CHECK: invalid
50 // CHECK: invalid
51 // CHECK: invalid
52
53 return 0;
54}
55

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/strtonum.cpp