aboutsummaryrefslogtreecommitdiff
path: root/libexec/flua
diff options
context:
space:
mode:
authorStefan Eßer <se@FreeBSD.org>2024-10-28 15:22:08 +0000
committerStefan Eßer <se@FreeBSD.org>2024-10-28 15:31:08 +0000
commitf35ccf46c7c6cb7d26994ec5dc5926ea53be0116 (patch)
treec49d2ef060f8e83a47b7f0bbd34bcd4c29998d7f /libexec/flua
parentb74aaa1a2199261f9078247d29481a994b6b5e42 (diff)
Diffstat (limited to 'libexec/flua')
-rw-r--r--libexec/flua/linit_flua.c1
-rw-r--r--libexec/flua/modules/lposix.c41
-rw-r--r--libexec/flua/modules/lposix.h1
3 files changed, 43 insertions, 0 deletions
diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c
index 5cae7531b7da..8eaa4af1ffca 100644
--- a/libexec/flua/linit_flua.c
+++ b/libexec/flua/linit_flua.c
@@ -57,6 +57,7 @@ static const luaL_Reg loadedlibs[] = {
#endif
/* FreeBSD Extensions */
{"lfs", luaopen_lfs},
+ {"posix.fnmatch", luaopen_posix_fnmatch},
{"posix.libgen", luaopen_posix_libgen},
{"posix.stdlib", luaopen_posix_stdlib},
{"posix.sys.stat", luaopen_posix_sys_stat},
diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c
index 77e152754b8c..0f3ea7722d4d 100644
--- a/libexec/flua/modules/lposix.c
+++ b/libexec/flua/modules/lposix.c
@@ -9,6 +9,7 @@
#include <sys/wait.h>
#include <errno.h>
+#include <fnmatch.h>
#include <grp.h>
#include <libgen.h>
#include <pwd.h>
@@ -165,6 +166,23 @@ err:
}
static int
+lua_fnmatch(lua_State *L)
+{
+ const char *pattern, *string;
+ int flags, n;
+
+ n = lua_gettop(L);
+ luaL_argcheck(L, n == 2 || n == 3, 4, "need 2 or 3 arguments");
+
+ pattern = luaL_checkstring(L, 1);
+ string = luaL_checkstring(L, 2);
+ flags = luaL_optinteger(L, 3, 0);
+ lua_pushinteger(L, fnmatch(pattern, string, flags));
+
+ return (1);
+}
+
+static int
lua_uname(lua_State *L)
{
struct utsname name;
@@ -462,6 +480,11 @@ static const struct luaL_Reg stdliblib[] = {
{ NULL, NULL },
};
+static const struct luaL_Reg fnmatchlib[] = {
+ REG_SIMPLE(fnmatch),
+ { NULL, NULL },
+};
+
static const struct luaL_Reg sys_statlib[] = {
REG_SIMPLE(chmod),
{ NULL, NULL },
@@ -507,6 +530,24 @@ luaopen_posix_stdlib(lua_State *L)
}
int
+luaopen_posix_fnmatch(lua_State *L)
+{
+ luaL_newlib(L, fnmatchlib);
+
+#define setkv(f) do { \
+ lua_pushinteger(L, f); \
+ lua_setfield(L, -2, #f); \
+} while (0)
+ setkv(FNM_PATHNAME);
+ setkv(FNM_NOESCAPE);
+ setkv(FNM_NOMATCH);
+ setkv(FNM_PERIOD);
+#undef setkv
+
+ return 1;
+}
+
+int
luaopen_posix_sys_stat(lua_State *L)
{
luaL_newlib(L, sys_statlib);
diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h
index 9d2c97b0d2dc..da7079056826 100644
--- a/libexec/flua/modules/lposix.h
+++ b/libexec/flua/modules/lposix.h
@@ -7,6 +7,7 @@
#include <lua.h>
+int luaopen_posix_fnmatch(lua_State *L);
int luaopen_posix_libgen(lua_State *L);
int luaopen_posix_stdlib(lua_State *L);
int luaopen_posix_sys_stat(lua_State *L);