Page MenuHomeFreeBSD

D46849.diff
No OneTemporary

D46849.diff

diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c
--- a/libexec/flua/linit_flua.c
+++ b/libexec/flua/linit_flua.c
@@ -57,6 +57,7 @@
#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.h b/libexec/flua/modules/lposix.h
--- 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);
diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c
--- 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>
@@ -164,6 +165,23 @@
}
+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)
{
@@ -462,6 +480,11 @@
{ 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 },
@@ -506,6 +529,24 @@
return (1);
}
+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)
{

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 20, 2:04 PM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17231258
Default Alt Text
D46849.diff (2 KB)

Event Timeline