* config.guess, config.sub, lib/argmatch.c, lib/argmatch.h,
[findutils.git] / lib / strtoumax.c
blobae57acebe8185d85b0cb2dd60627db5ff7fa1d14
1 /* Convert string representation of a number into an uintmax_t value.
2 Copyright 1999 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by Paul Eggert. */
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #if HAVE_INTTYPES_H
25 # include <inttypes.h>
26 #endif
28 #if HAVE_STDLIB_H
29 # include <stdlib.h>
30 #endif
32 #ifndef PARAMS
33 # if defined PROTOTYPES || defined __STDC__
34 # define PARAMS(Args) Args
35 # else
36 # define PARAMS(Args) ()
37 # endif
38 #endif
40 #if NEED_STRTOUL_DECL
41 unsigned long strtoul PARAMS ((char const *, char **, int));
42 #endif
44 #if NEED_STRTOULL_DECL && HAVE_UNSIGNED_LONG_LONG
45 unsigned long long strtoull PARAMS ((char const *, char **, int));
46 #endif
48 uintmax_t
49 strtoumax (char const *ptr, char **endptr, int base)
51 #define USE_IF_EQUIVALENT(function) \
52 if (sizeof (uintmax_t) == sizeof function (ptr, endptr, base)) \
53 return function (ptr, endptr, base);
55 #if HAVE_UNSIGNED_LONG_LONG
56 USE_IF_EQUIVALENT (strtoull)
57 #endif
59 USE_IF_EQUIVALENT (strtoul)
61 abort ();
64 #ifdef TESTING
65 # include <stdio.h>
66 int
67 main ()
69 char *p, *endptr;
70 printf ("sizeof uintmax_t: %d\n", sizeof (uintmax_t));
71 printf ("sizeof strtoull(): %d\n", sizeof strtoull(p, &endptr, 10));
72 printf ("sizeof strtoul(): %d\n", sizeof strtoul(p, &endptr, 10));
73 exit (0);
75 #endif