Skip to content

Commit e3eed7f

Browse files
nickalcockgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f696543 commit e3eed7f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ all::
5757
#
5858
# Define NO_STRLCPY if you don't have strlcpy.
5959
#
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
6262
# strtoull, define NO_STRTOULL.
6363
#
6464
# Define NO_SETENV if you don't have setenv in the C library.
@@ -1402,7 +1402,7 @@ ifdef NO_STRLCPY
14021402
endif
14031403
ifdef NO_STRTOUMAX
14041404
COMPAT_CFLAGS += -DNO_STRTOUMAX
1405-
COMPAT_OBJS += compat/strtoumax.o
1405+
COMPAT_OBJS += compat/strtoumax.o compat/strtoimax.o
14061406
endif
14071407
ifdef NO_STRTOULL
14081408
COMPAT_CFLAGS += -DNO_STRTOULL

compat/strtoimax.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)