summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--git-compat-util.h13
2 files changed, 15 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index e11e626d05..c6dc42d067 100644
--- a/Makefile
+++ b/Makefile
@@ -296,7 +296,8 @@ all::
# Define USE_NED_ALLOCATOR if you want to replace the platforms default
# memory allocators with the nedmalloc allocator written by Niall Douglas.
#
-# Define NO_REGEX if you have no or inferior regex support in your C library.
+# Define NO_REGEX if your C library lacks regex support with REG_STARTEND
+# feature.
#
# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
# user.
diff --git a/git-compat-util.h b/git-compat-util.h
index 1f8b5f3b1f..7047d281e5 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -942,6 +942,19 @@ void git_qsort(void *base, size_t nmemb, size_t size,
#define qsort git_qsort
#endif
+#ifndef REG_STARTEND
+#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
+#endif
+
+static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
+ size_t nmatch, regmatch_t pmatch[], int eflags)
+{
+ assert(nmatch > 0 && pmatch);
+ pmatch[0].rm_so = 0;
+ pmatch[0].rm_eo = size;
+ return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
+}
+
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
# define FORCE_DIR_SET_GID S_ISGID
#else