Simplify strchrnul() compat code
strchrnul() was introduced in glibc in April 1999 and included in glibc-2.1. Checking for that version means the majority of all git users would get to use the optimized version in glibc. Of the remaining few some might get to use a slightly slower version than necessary but probably not slower than what we have today. Unfortunately, __GLIBC_PREREQ() macro was not available in glibc 2.1.1 which was short lived but already supported strchrnul(). Odd minority users of that library needs to live with our compatibility inline version. Rediffed-against-next-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andreas Ericsson committed
Nov 10, 2007 at 12:55 UTC
9e79f00f06a5500b30941e6925adda070504e6cf
3 files changed
+7
-23
Makefile
-13
@@ -30,8 +30,6 @@ all::
30
#
31
# Define NO_MEMMEM if you don't have memmem.
32
#
33
-# Define NO_STRCHRNUL if you don't have strchrnul.
34
-#
33
# Define NO_STRLCPY if you don't have strlcpy.
34
#
35
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
@@ -408,7 +406,6 @@ ifeq ($(uname_S),Darwin)
406
OLD_ICONV = UnfortunatelyYes
407
NO_STRLCPY = YesPlease
408
NO_MEMMEM = YesPlease
411
- NO_STRCHRNUL = YesPlease
409
endif
410
ifeq ($(uname_S),SunOS)
411
NEEDS_SOCKET = YesPlease
@@ -416,7 +413,6 @@ ifeq ($(uname_S),SunOS)
413
SHELL_PATH = /bin/bash
414
NO_STRCASESTR = YesPlease
415
NO_MEMMEM = YesPlease
419
- NO_STRCHRNUL = YesPlease
416
NO_HSTRERROR = YesPlease
417
ifeq ($(uname_R),5.8)
418
NEEDS_LIBICONV = YesPlease
@@ -442,7 +438,6 @@ ifeq ($(uname_O),Cygwin)
438
NO_D_INO_IN_DIRENT = YesPlease
439
NO_STRCASESTR = YesPlease
440
NO_MEMMEM = YesPlease
445
- NO_STRCHRNUL = YesPlease
441
NO_SYMLINK_HEAD = YesPlease
442
NEEDS_LIBICONV = YesPlease
443
NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
@@ -457,14 +452,12 @@ endif
452
ifeq ($(uname_S),FreeBSD)
453
NEEDS_LIBICONV = YesPlease
454
NO_MEMMEM = YesPlease
460
- NO_STRCHRNUL = YesPlease
455
BASIC_CFLAGS += -I/usr/local/include
456
BASIC_LDFLAGS += -L/usr/local/lib
457
endif
458
ifeq ($(uname_S),OpenBSD)
459
NO_STRCASESTR = YesPlease
460
NO_MEMMEM = YesPlease
467
- NO_STRCHRNUL = YesPlease
461
NEEDS_LIBICONV = YesPlease
462
BASIC_CFLAGS += -I/usr/local/include
463
BASIC_LDFLAGS += -L/usr/local/lib
@@ -480,7 +473,6 @@ endif
473
ifeq ($(uname_S),AIX)
474
NO_STRCASESTR=YesPlease
475
NO_MEMMEM = YesPlease
483
- NO_STRCHRNUL = YesPlease
476
NO_STRLCPY = YesPlease
477
NEEDS_LIBICONV=YesPlease
478
endif
@@ -493,7 +485,6 @@ ifeq ($(uname_S),IRIX64)
485
NO_SETENV=YesPlease
486
NO_STRCASESTR=YesPlease
487
NO_MEMMEM = YesPlease
496
- NO_STRCHRNUL = YesPlease
488
NO_STRLCPY = YesPlease
489
NO_SOCKADDR_STORAGE=YesPlease
490
SHELL_PATH=/usr/gnu/bin/bash
@@ -704,10 +695,6 @@ ifdef NO_MEMMEM
695
COMPAT_CFLAGS += -DNO_MEMMEM
696
COMPAT_OBJS += compat/memmem.o
697
endif
707
-ifdef NO_STRCHRNUL
708
- COMPAT_CFLAGS += -DNO_STRCHRNUL
709
- COMPAT_OBJS += compat/strchrnul.o
710
-endif
698
699
ifdef THREADED_DELTA_SEARCH
700
BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
compat/strchrnul.c
deleted
-8
@@ -1,8 +0,0 @@
1
-#include "../git-compat-util.h"
2
-
3
-char *gitstrchrnul(const char *s, int c)
4
-{
5
- while (*s && *s != c)
6
- s++;
7
- return (char *)s;
8
-}
git-compat-util.h
+7
-2
@@ -183,9 +183,14 @@ void *gitmemmem(const void *haystack, size_t haystacklen,
183
const void *needle, size_t needlelen);
184
#endif
185
186
-#ifdef NO_STRCHRNUL
186
+#if !defined(__GLIBC_PREREQ) && !__GLIBC_PREREQ(2, 1)
187
#define strchrnul gitstrchrnul
188
-char *gitstrchrnul(const char *s, int c);
188
+static inline char *gitstrchrnul(const char *s, int c)
189
+{
190
+ while (*s && *s != c)
191
+ s++;
192
+ return (char *)s;
193
+}
194
#endif
195
196
extern void release_pack_memory(size_t, int);