Skip to content

Commit

Permalink
win32: don't include regex by default
Browse files Browse the repository at this point in the history
Windows doesn't have a regex library (or regex.h) by default. Don't try
to compile it in unless `XDL_REGEX` is defined. Otherwise, error with
`REG_ASSERT` if the regex functionality is attempted to be used.
  • Loading branch information
ethomson committed Dec 15, 2023
1 parent 3b90a9d commit 75da4b6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions git-xdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <regex.h>

/* Work around C90-conformance issues */
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
Expand Down Expand Up @@ -47,8 +46,23 @@

#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0)

#define xdl_regex_t regex_t
#define xdl_regmatch_t regmatch_t
#if defined(_MSC_VER) && !defined(XDL_REGEX)

# define xdl_regex_t void *
# define xdl_regmatch_t void *

inline int xdl_regex_buf(
const xdl_regex_t *preg, const char *buf, size_t size,
size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
{
return 15; /* REG_ASSERT */
}

#else
# include <regex.h>

# define xdl_regex_t regex_t
# define xdl_regmatch_t regmatch_t

inline int xdl_regexec_buf(
const xdl_regex_t *preg, const char *buf, size_t size,
Expand All @@ -60,4 +74,6 @@ inline int xdl_regexec_buf(
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
}

#endif /* XDL_NO_REGEX */

#endif

0 comments on commit 75da4b6

Please sign in to comment.