Import upstream version 1.28
[debian/tar] / gnu / strtoimax.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Convert string representation of a number into an intmax_t value.
4
5    Copyright (C) 1999, 2001-2004, 2006, 2009-2014 Free Software Foundation,
6    Inc.
7
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 /* Written by Paul Eggert. */
22
23 #include <config.h>
24
25 /* Verify interface.  */
26 #include <inttypes.h>
27
28 #include <stdlib.h>
29
30 #include "verify.h"
31
32 #ifdef UNSIGNED
33 # if HAVE_UNSIGNED_LONG_LONG_INT
34 #  ifndef HAVE_DECL_STRTOULL
35 "this configure-time declaration test was not run"
36 #  endif
37 #  if !HAVE_DECL_STRTOULL
38 unsigned long long int strtoull (char const *, char **, int);
39 #  endif
40 # endif
41
42 #else
43
44 # if HAVE_LONG_LONG_INT
45 #  ifndef HAVE_DECL_STRTOLL
46 "this configure-time declaration test was not run"
47 #  endif
48 #  if !HAVE_DECL_STRTOLL
49 long long int strtoll (char const *, char **, int);
50 #  endif
51 # endif
52 #endif
53
54 #ifdef UNSIGNED
55 # define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT
56 # define Int uintmax_t
57 # define Strtoimax strtoumax
58 # define Strtol strtoul
59 # define Strtoll strtoull
60 # define Unsigned unsigned
61 #else
62 # define Have_long_long HAVE_LONG_LONG_INT
63 # define Int intmax_t
64 # define Strtoimax strtoimax
65 # define Strtol strtol
66 # define Strtoll strtoll
67 # define Unsigned
68 #endif
69
70 Int
71 Strtoimax (char const *ptr, char **endptr, int base)
72 {
73 #if Have_long_long
74   verify (sizeof (Int) == sizeof (Unsigned long int)
75           || sizeof (Int) == sizeof (Unsigned long long int));
76
77   if (sizeof (Int) != sizeof (Unsigned long int))
78     return Strtoll (ptr, endptr, base);
79 #else
80   verify (sizeof (Int) == sizeof (Unsigned long int));
81 #endif
82
83   return Strtol (ptr, endptr, base);
84 }