Skip to content

Commit 77b9f1b

Browse files
committed
win32: don't include regex by default
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.
1 parent 3b90a9d commit 77b9f1b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

git-xdiff.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <stdint.h>
1717
#include <stdio.h>
1818
#include <string.h>
19-
#include <regex.h>
2019

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

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

50-
#define xdl_regex_t regex_t
51-
#define xdl_regmatch_t regmatch_t
49+
#if defined(_MSC_VER) && !defined(XDL_REGEX)
50+
51+
# define xdl_regex_t void *
52+
# define xdl_regmatch_t void *
53+
54+
inline int xdl_regexec_buf(
55+
const xdl_regex_t *preg, const char *buf, size_t size,
56+
size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
57+
{
58+
return 15; /* REG_ASSERT */
59+
}
60+
61+
#else
62+
# include <regex.h>
63+
64+
# define xdl_regex_t regex_t
65+
# define xdl_regmatch_t regmatch_t
5266

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

77+
#endif /* XDL_NO_REGEX */
78+
6379
#endif

0 commit comments

Comments
 (0)