brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 4d0d8b3 Raw
44 lines · cpp
1// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s2 3#include <inttypes.h>4#include <stdio.h>5 6void 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("strtoi: conversion of '%s' to a number %s, using %jd, p=%#" PRIx811         "\n",12         nptr, status ? "failed" : "successful", i, *p);13}14 15void 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("strtou: conversion of '%s' to a number %s, using %ju, p=%#" PRIx820         "\n",21         nptr, status ? "failed" : "successful", i, *p);22}23 24int main(void) {25  printf("strtoi\n");26 27  test_strtoi("100", 0, 1, 100);28  test_strtoi("100", 0, 1, 10);29  test_strtoi("100xyz", 0, 1, 100);30  test_strtou("100", 0, 1, 100);31  test_strtou("100", 0, 1, 10);32  test_strtou("100xyz", 0, 1, 100);33 34  // CHECK: strtoi35  // CHECK: strtoi: conversion of '100' to a number successful, using 100, p=036  // CHECK: strtoi: conversion of '100' to a number failed, using 10, p=037  // CHECK: strtoi: conversion of '100xyz' to a number failed, using 100, p=0x7838  // CHECK: strtou: conversion of '100' to a number successful, using 100, p=039  // CHECK: strtou: conversion of '100' to a number failed, using 10, p=040  // CHECK: strtou: conversion of '100xyz' to a number failed, using 100, p=0x7841 42  return 0;43}44