Add strchrnul()
As suggested by Pierre Habouzit, add strchrnul(). It's a useful GNU extension and can simplify string parser code. There are several places in git that can be converted to strchrnul(); as a trivial example, this patch introduces its usage to builtin-fetch--tool.c. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c238dad407
commit
659c69cfef
13
Makefile
13
Makefile
@ -30,6 +30,8 @@ all::
|
|||||||
#
|
#
|
||||||
# Define NO_MEMMEM if you don't have memmem.
|
# Define NO_MEMMEM if you don't have memmem.
|
||||||
#
|
#
|
||||||
|
# Define NO_STRCHRNUL if you don't have strchrnul.
|
||||||
|
#
|
||||||
# Define NO_STRLCPY if you don't have strlcpy.
|
# Define NO_STRLCPY if you don't have strlcpy.
|
||||||
#
|
#
|
||||||
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
|
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
|
||||||
@ -406,6 +408,7 @@ ifeq ($(uname_S),Darwin)
|
|||||||
OLD_ICONV = UnfortunatelyYes
|
OLD_ICONV = UnfortunatelyYes
|
||||||
NO_STRLCPY = YesPlease
|
NO_STRLCPY = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
endif
|
endif
|
||||||
ifeq ($(uname_S),SunOS)
|
ifeq ($(uname_S),SunOS)
|
||||||
NEEDS_SOCKET = YesPlease
|
NEEDS_SOCKET = YesPlease
|
||||||
@ -413,6 +416,7 @@ ifeq ($(uname_S),SunOS)
|
|||||||
SHELL_PATH = /bin/bash
|
SHELL_PATH = /bin/bash
|
||||||
NO_STRCASESTR = YesPlease
|
NO_STRCASESTR = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
NO_HSTRERROR = YesPlease
|
NO_HSTRERROR = YesPlease
|
||||||
ifeq ($(uname_R),5.8)
|
ifeq ($(uname_R),5.8)
|
||||||
NEEDS_LIBICONV = YesPlease
|
NEEDS_LIBICONV = YesPlease
|
||||||
@ -438,6 +442,7 @@ ifeq ($(uname_O),Cygwin)
|
|||||||
NO_D_INO_IN_DIRENT = YesPlease
|
NO_D_INO_IN_DIRENT = YesPlease
|
||||||
NO_STRCASESTR = YesPlease
|
NO_STRCASESTR = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
NO_SYMLINK_HEAD = YesPlease
|
NO_SYMLINK_HEAD = YesPlease
|
||||||
NEEDS_LIBICONV = YesPlease
|
NEEDS_LIBICONV = YesPlease
|
||||||
NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
|
NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
|
||||||
@ -452,12 +457,14 @@ endif
|
|||||||
ifeq ($(uname_S),FreeBSD)
|
ifeq ($(uname_S),FreeBSD)
|
||||||
NEEDS_LIBICONV = YesPlease
|
NEEDS_LIBICONV = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
BASIC_CFLAGS += -I/usr/local/include
|
BASIC_CFLAGS += -I/usr/local/include
|
||||||
BASIC_LDFLAGS += -L/usr/local/lib
|
BASIC_LDFLAGS += -L/usr/local/lib
|
||||||
endif
|
endif
|
||||||
ifeq ($(uname_S),OpenBSD)
|
ifeq ($(uname_S),OpenBSD)
|
||||||
NO_STRCASESTR = YesPlease
|
NO_STRCASESTR = YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
NEEDS_LIBICONV = YesPlease
|
NEEDS_LIBICONV = YesPlease
|
||||||
BASIC_CFLAGS += -I/usr/local/include
|
BASIC_CFLAGS += -I/usr/local/include
|
||||||
BASIC_LDFLAGS += -L/usr/local/lib
|
BASIC_LDFLAGS += -L/usr/local/lib
|
||||||
@ -473,6 +480,7 @@ endif
|
|||||||
ifeq ($(uname_S),AIX)
|
ifeq ($(uname_S),AIX)
|
||||||
NO_STRCASESTR=YesPlease
|
NO_STRCASESTR=YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
NO_STRLCPY = YesPlease
|
NO_STRLCPY = YesPlease
|
||||||
NEEDS_LIBICONV=YesPlease
|
NEEDS_LIBICONV=YesPlease
|
||||||
endif
|
endif
|
||||||
@ -485,6 +493,7 @@ ifeq ($(uname_S),IRIX64)
|
|||||||
NO_SETENV=YesPlease
|
NO_SETENV=YesPlease
|
||||||
NO_STRCASESTR=YesPlease
|
NO_STRCASESTR=YesPlease
|
||||||
NO_MEMMEM = YesPlease
|
NO_MEMMEM = YesPlease
|
||||||
|
NO_STRCHRNUL = YesPlease
|
||||||
NO_STRLCPY = YesPlease
|
NO_STRLCPY = YesPlease
|
||||||
NO_SOCKADDR_STORAGE=YesPlease
|
NO_SOCKADDR_STORAGE=YesPlease
|
||||||
SHELL_PATH=/usr/gnu/bin/bash
|
SHELL_PATH=/usr/gnu/bin/bash
|
||||||
@ -695,6 +704,10 @@ ifdef NO_MEMMEM
|
|||||||
COMPAT_CFLAGS += -DNO_MEMMEM
|
COMPAT_CFLAGS += -DNO_MEMMEM
|
||||||
COMPAT_OBJS += compat/memmem.o
|
COMPAT_OBJS += compat/memmem.o
|
||||||
endif
|
endif
|
||||||
|
ifdef NO_STRCHRNUL
|
||||||
|
COMPAT_CFLAGS += -DNO_STRCHRNUL
|
||||||
|
COMPAT_OBJS += compat/strchrnul.o
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef THREADED_DELTA_SEARCH
|
ifdef THREADED_DELTA_SEARCH
|
||||||
BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
|
BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
|
||||||
|
@ -435,9 +435,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu
|
|||||||
cp++;
|
cp++;
|
||||||
if (!*cp)
|
if (!*cp)
|
||||||
break;
|
break;
|
||||||
np = strchr(cp, '\n');
|
np = strchrnul(cp, '\n');
|
||||||
if (!np)
|
|
||||||
np = cp + strlen(cp);
|
|
||||||
if (pass) {
|
if (pass) {
|
||||||
lrr_list[i].line = cp;
|
lrr_list[i].line = cp;
|
||||||
lrr_list[i].name = cp + 41;
|
lrr_list[i].name = cp + 41;
|
||||||
@ -461,9 +459,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu
|
|||||||
rref++;
|
rref++;
|
||||||
if (!*rref)
|
if (!*rref)
|
||||||
break;
|
break;
|
||||||
next = strchr(rref, '\n');
|
next = strchrnul(rref, '\n');
|
||||||
if (!next)
|
|
||||||
next = rref + strlen(rref);
|
|
||||||
rreflen = next - rref;
|
rreflen = next - rref;
|
||||||
|
|
||||||
for (i = 0; i < lrr_count; i++) {
|
for (i = 0; i < lrr_count; i++) {
|
||||||
|
8
compat/strchrnul.c
Normal file
8
compat/strchrnul.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "../git-compat-util.h"
|
||||||
|
|
||||||
|
char *gitstrchrnul(const char *s, int c)
|
||||||
|
{
|
||||||
|
while (*s && *s != c)
|
||||||
|
s++;
|
||||||
|
return (char *)s;
|
||||||
|
}
|
@ -183,6 +183,11 @@ void *gitmemmem(const void *haystack, size_t haystacklen,
|
|||||||
const void *needle, size_t needlelen);
|
const void *needle, size_t needlelen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef NO_STRCHRNUL
|
||||||
|
#define strchrnul gitstrchrnul
|
||||||
|
char *gitstrchrnul(const char *s, int c);
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void release_pack_memory(size_t, int);
|
extern void release_pack_memory(size_t, int);
|
||||||
|
|
||||||
static inline char* xstrdup(const char *str)
|
static inline char* xstrdup(const char *str)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user