Skip to content

Commit

Permalink
Add strtoimax() compatibility function.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
nickalcock authored and gitster committed Nov 2, 2011
1 parent f696543 commit e3eed7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ all::
#
# Define NO_STRLCPY if you don't have strlcpy.
#
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
# If your compiler also does not support long long or does not have
# Define NO_STRTOUMAX if you don't have both strtoimax and strtoumax in the
# C library. If your compiler also does not support long long or does not have
# strtoull, define NO_STRTOULL.
#
# Define NO_SETENV if you don't have setenv in the C library.
Expand Down Expand Up @@ -1402,7 +1402,7 @@ ifdef NO_STRLCPY
endif
ifdef NO_STRTOUMAX
COMPAT_CFLAGS += -DNO_STRTOUMAX
COMPAT_OBJS += compat/strtoumax.o
COMPAT_OBJS += compat/strtoumax.o compat/strtoimax.o
endif
ifdef NO_STRTOULL
COMPAT_CFLAGS += -DNO_STRTOULL
Expand Down
10 changes: 10 additions & 0 deletions compat/strtoimax.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "../git-compat-util.h"

intmax_t gitstrtoimax (const char *nptr, char **endptr, int base)
{
#if defined(NO_STRTOULL)
return strtol(nptr, endptr, base);
#else
return strtoll(nptr, endptr, base);
#endif
}

0 comments on commit e3eed7f

Please sign in to comment.