diff --git a/build/detect-fnm-extmatch.c b/build/detect-fnm-extmatch.c new file mode 100644 index 000000000..afa35b633 --- /dev/null +++ b/build/detect-fnm-extmatch.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + int x = FNM_EXTMATCH; + return 0; +} diff --git a/build/detect-glob-period.c b/build/detect-glob-period.c new file mode 100644 index 000000000..aa9665681 --- /dev/null +++ b/build/detect-glob-period.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + int x = GLOB_PERIOD; + return 0; +} diff --git a/configure b/configure index a7c0f1b9d..a740276ca 100755 --- a/configure +++ b/configure @@ -445,6 +445,24 @@ echo_cpp() { else echo '/* #undef HAVE_PWENT */' fi + + # Check if non-POSIX GLOB_PERIOD is available + if cc_quiet build/detect-glob-period.c; then + echo '/* libc defines GLOB_PERIOD */' + else + # INVALID value that we can detect in code + # e.g. Android does not support this, but glibc and musl libc do + echo '#define GLOB_PERIOD 0' + fi + + # Check if non-POSIX GLOB_PERIOD is available + if cc_quiet build/detect-fnm-extmatch.c; then + echo '/* libc defines FNM_EXTMATCH */' + else + # INVALID value that we can detect in code + # e.g. musl libc does not support this, but glibc does + echo '#define FNM_EXTMATCH 0' + fi } # Another way of working: set detected-config.mk ? diff --git a/doc/portability.md b/doc/portability.md index 085e75a5e..d1f7d675c 100644 --- a/doc/portability.md +++ b/doc/portability.md @@ -14,16 +14,24 @@ These are some notes that supplement [INSTALL](INSTALL.html). ## Issues in the core of Oils -### GNU libc for extended globs +### libc - `FNM_EXTMATCH` is not in POSIX -For matching extended globs like `@(*.cc|*.h)`, Oils relies on GNU libc -support. +To match extended globs like `@(*.cc|*.h)`, OSH relies on `FNM_EXTMATCH` from +GNU libc. -- This is not a POSIX feature. -- It's also unlike bash, which has its own extended glob support. +This is unlike bash, which has its own extended glob library. TODO: when using other libc, using this syntax should be an error. +### libc - `GLOB_PERIOD` is not in POSIX + +To implement the bash feature `shopt -s dotglob`, OSH relies on `GLOB_PERIOD`, +which some libc's implement. + +This is unlike bash, which has its own glob library. + +TODO: `shopt -s dotglob` should give a warning when turned on. + ### Atomic Assignments The signal handler assumes that int and pointer assignments are atomic. This diff --git a/pyext/libc.c b/pyext/libc.c index c6384dc09..0ad522497 100644 --- a/pyext/libc.c +++ b/pyext/libc.c @@ -411,6 +411,7 @@ void initlibc(void) { module = Py_InitModule("libc", methods); if (module != NULL) { PyModule_AddIntConstant(module, "GLOB_PERIOD", GLOB_PERIOD); + PyModule_AddIntConstant(module, "FNM_EXTMATCH", FNM_EXTMATCH); PyModule_AddIntConstant(module, "FNM_CASEFOLD", FNM_CASEFOLD); PyModule_AddIntConstant(module, "REG_ICASE", REG_ICASE); PyModule_AddIntConstant(module, "REG_NEWLINE", REG_NEWLINE); diff --git a/pyext/libc_test.py b/pyext/libc_test.py index 345299b8e..f8826ac5e 100755 --- a/pyext/libc_test.py +++ b/pyext/libc_test.py @@ -20,6 +20,10 @@ class LibcTest(unittest.TestCase): + def testConstants(self): + print('GLOB_PERIOD %d' % libc.GLOB_PERIOD) + print('FNM_EXTMATCH %d' % libc.FNM_EXTMATCH) + def testFnmatch(self): cases = [