Skip to content

Commit bc6b4f5

Browse files
Jason RiedyJunio C Hamano
authored andcommitted
Add a compat/strtoumax.c for Solaris 8.
Solaris 8 was pre-c99, and they weren't willing to commit to the strtoumax definition according to /usr/include/inttypes.h. This adds NO_STRTOUMAX and NO_STRTOULL for ancient systems. If NO_STRTOUMAX is defined, the routine in compat/strtoumax.c will be used instead. That routine passes its arguments to strtoull unless NO_STRTOULL is defined. If NO_STRTOULL, then the routine uses strtoul (unsigned long). Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu> Acked-by: Shawn O Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent f496454 commit bc6b4f5

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ all::
2828
#
2929
# Define NO_STRLCPY if you don't have strlcpy.
3030
#
31+
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
32+
# If your compiler also does not support long long or does not have
33+
# strtoull, define NO_STRTOULL.
34+
#
3135
# Define NO_SETENV if you don't have setenv in the C library.
3236
#
3337
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
@@ -353,11 +357,13 @@ ifeq ($(uname_S),SunOS)
353357
NO_UNSETENV = YesPlease
354358
NO_SETENV = YesPlease
355359
NO_C99_FORMAT = YesPlease
360+
NO_STRTOUMAX = YesPlease
356361
endif
357362
ifeq ($(uname_R),5.9)
358363
NO_UNSETENV = YesPlease
359364
NO_SETENV = YesPlease
360365
NO_C99_FORMAT = YesPlease
366+
NO_STRTOUMAX = YesPlease
361367
endif
362368
INSTALL = ginstall
363369
TAR = gtar
@@ -517,6 +523,13 @@ ifdef NO_STRLCPY
517523
COMPAT_CFLAGS += -DNO_STRLCPY
518524
COMPAT_OBJS += compat/strlcpy.o
519525
endif
526+
ifdef NO_STRTOUMAX
527+
COMPAT_CFLAGS += -DNO_STRTOUMAX
528+
COMPAT_OBJS += compat/strtoumax.o
529+
endif
530+
ifdef NO_STRTOULL
531+
COMPAT_CFLAGS += -DNO_STRTOULL
532+
endif
520533
ifdef NO_SETENV
521534
COMPAT_CFLAGS += -DNO_SETENV
522535
COMPAT_OBJS += compat/setenv.o

compat/strtoumax.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+
uintmax_t gitstrtoumax (const char *nptr, char **endptr, int base)
4+
{
5+
#if defined(NO_STRTOULL)
6+
return strtoul(nptr, endptr, base);
7+
#else
8+
return strtoull(nptr, endptr, base);
9+
#endif
10+
}

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ extern char *gitstrcasestr(const char *haystack, const char *needle);
139139
extern size_t gitstrlcpy(char *, const char *, size_t);
140140
#endif
141141

142+
#ifdef NO_STRTOUMAX
143+
#define strtoumax gitstrtoumax
144+
extern uintmax_t gitstrtoumax(const char *, char **, int);
145+
#endif
146+
142147
extern void release_pack_memory(size_t);
143148

144149
static inline char* xstrdup(const char *str)

0 commit comments

Comments
 (0)