Add strtoimax() compatibility function.

Since systems that omit strtoumax() will likely omit strtomax() too, and likewise for strtoull() and strtoll(), we arrange for the make variables NO_STRTOUMAX and NO_STRTOULL to cover both the signed and unsigned functions, and define compatibility implementations for them. Signed-off-by: Nick Alcock <nix@esperi.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nick Alcock committed Nov 2, 2011 at 15:46 UTC e3eed7f8d238e895922851315447f5df9c475f11
2 files changed +13 -3
Makefile
+3 -3
@@ -57,8 +57,8 @@ all::
57 #
58 # Define NO_STRLCPY if you don't have strlcpy.
59 #
60 -# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
61 -# If your compiler also does not support long long or does not have
60 +# Define NO_STRTOUMAX if you don't have both strtoimax and strtoumax in the
61 +# C library. If your compiler also does not support long long or does not have
62 # strtoull, define NO_STRTOULL.
63 #
64 # Define NO_SETENV if you don't have setenv in the C library.
@@ -1402,7 +1402,7 @@ ifdef NO_STRLCPY
1402 endif
1403 ifdef NO_STRTOUMAX
1404 COMPAT_CFLAGS += -DNO_STRTOUMAX
1405 - COMPAT_OBJS += compat/strtoumax.o
1405 + COMPAT_OBJS += compat/strtoumax.o compat/strtoimax.o
1406 endif
1407 ifdef NO_STRTOULL
1408 COMPAT_CFLAGS += -DNO_STRTOULL
compat/strtoimax.c new
+10
@@ -0,0 +1,10 @@
1 +#include "../git-compat-util.h"
2 +
3 +intmax_t gitstrtoimax (const char *nptr, char **endptr, int base)
4 +{
5 +#if defined(NO_STRTOULL)
6 + return strtol(nptr, endptr, base);
7 +#else
8 + return strtoll(nptr, endptr, base);
9 +#endif
10 +}