git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Add strtoimax() compatibility function.

From
Nick Alcock <nix@esperi.org.uk>
Date
Nov 2, 2011, 15:46 UTC
Message-ID
<1320248783-29577-2-git-send-email-nix@esperi.org.uk>
In-Reply-To
<1320248783-29577-1-git-send-email-nix@esperi.org.uk>

Since systems that omit strtoumax() will likely omit strtomax() too, and likewise for strtoull() and strtoll(), we arrange for the compatibility #defines NO_STRTOUMAX and NO_STRTOULL to cover both the signed and unsigned functions. (We cannot change their names without breaking existing makefile configurations.)

Signed-off-by: Nick Alcock <nix@esperi.org.uk>
---
 Makefile           |    6 +++---
 compat/strtoimax.c |   10 ++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 compat/strtoimax.c
diff --git a/Makefile b/Makefile
index 303a8df..a1f7e34 100644
--- a/Makefile
+++ b/Makefile
@@ -58,8 +58,8 @@ include /home/compiler/.configure/site.mk
 #
 # 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.
@@ -1459,7 +1459,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
diff --git a/compat/strtoimax.c b/compat/strtoimax.c
new file mode 100644
index 0000000..ac09ed8
--- /dev/null
+++ b/compat/strtoimax.c
@@ -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
+}
-- 
1.7.6.1.138.g03ab.dirty
Previous: Nick AlcockNext: Nick Alcock
Message 2 of 3 in “Support sizes >=2G in various config options, v2”
  1. 0/2 Support sizes >=2G in various config options, v2Nick Alcock, Nov 2, 2011
  2. 1/2 Add strtoimax() compatibility function.Nick Alcock, Nov 2, 2011
  3. 2/2 Support sizes >=2G in various config options accepting 'g' sizes.Nick Alcock, Nov 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.