]> git.cworth.org Git - tar/blob - gnu/strtoimax.c
upstream: Fix extraction of device nodes.
[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, 2002, 2003, 2004, 2006, 2009, 2010 Free Software
6    Foundation, 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 # ifndef HAVE_DECL_STRTOULL
34 "this configure-time declaration test was not run"
35 # endif
36 # if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG_INT
37 unsigned long long int strtoull (char const *, char **, int);
38 # endif
39
40 #else
41
42 # ifndef HAVE_DECL_STRTOLL
43 "this configure-time declaration test was not run"
44 # endif
45 # if !HAVE_DECL_STRTOLL && HAVE_LONG_LONG_INT
46 long long int strtoll (char const *, char **, int);
47 # endif
48 #endif
49
50 #ifdef UNSIGNED
51 # define Have_long_long HAVE_UNSIGNED_LONG_LONG_INT
52 # define Int uintmax_t
53 # define Unsigned unsigned
54 # define strtoimax strtoumax
55 # define strtol strtoul
56 # define strtoll strtoull
57 #else
58 # define Have_long_long HAVE_LONG_LONG_INT
59 # define Int intmax_t
60 # define Unsigned
61 #endif
62
63 Int
64 strtoimax (char const *ptr, char **endptr, int base)
65 {
66 #if Have_long_long
67   verify (sizeof (Int) == sizeof (Unsigned long int)
68           || sizeof (Int) == sizeof (Unsigned long long int));
69
70   if (sizeof (Int) != sizeof (Unsigned long int))
71     return strtoll (ptr, endptr, base);
72 #else
73   verify (sizeof (Int) == sizeof (Unsigned long int));
74 #endif
75
76   return strtol (ptr, endptr, base);
77 }