From nobody Mon Oct 28 15:31:51 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XccnN1zr3z5bTQh; Mon, 28 Oct 2024 15:31:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XccnM71rPz40LJ; Mon, 28 Oct 2024 15:31:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730129512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gsrxrhl005K3bN0kWLlhTKV0waDhsJD8i72+qPZOE/0=; b=k+cgnYKMhoXjV2hE+gqgb6YItAOKe/kb6y9IoGXliLOlOda/UsT3HBslm0ptHcvg6Ysqe7 xZnGkyA6xJJkNDVUu+Z42EBww3UmUFKX9nfshRtXT3gkcB0dsnuroNhA3gZwBcU1YJP9/G QSDqxNT3WeebSWmCCiprXlwom3shYlboloy/8bB9NOTT+A0cipg4f645bwi2jKXdIfFW/P ePrupA65nvvW+kTZf8LTCCBtcv4oKEi1OGE0QsSDxG5wfjU/UdKytwTJEfBP4Ypx9PP+30 QrZE6PDLaLvsneGIuA6BAMNq6m6uVmKK8R0tH9MTtM4QM3wKI1H/thWEn7Y7Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730129512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gsrxrhl005K3bN0kWLlhTKV0waDhsJD8i72+qPZOE/0=; b=jVl79LE5gC+2aRguzB2mce1zlIHOiCWru5P00/3gQkBHPFq1izGCXFzCq4q7SxU29xb5B7 HUH3UPeFhIoMpv0Zh2r3GJAxMsTfxRRGv81+Ly4s2EU7ONMaF0hRt/4LlGr78oHO36crnA /U/xkPhC9wxQ5KxXsNbMLSEg2n1PHVzQ3zpofKThEt68k6qXIYBrohkznCnWs4MX60ObDW AaPR0ntvO8OtwybrlX0AxvF5Dbd6mDWRW0/yu3dNG7nNv9h3XjFau1wMYf1fK7MbfxipEa RigFvpw05YyAiSrv3JYp880Gg8rAaaLbFD+blrm1+PHOhA/XZwLQWLVnkTqAdA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730129512; a=rsa-sha256; cv=none; b=i2REfPTsP+8uCAGAt1vsGNQPi+SxZ6HYn84EAkfwOVKodwK5s5/fgH6oTdANF5NHv4GPo6 d6RJp+r4T3G1duziOTr6fFfcJLW4+D+R2EpGw6AY7UgYYwLzWJH7oOkyakzwK3bwv6rgWD BxClFWpQ8NToX7mAWHhg4hWPUffWwcPXaFUNJVba0mwL02n+mNLGb9K+6bZUm0nMn5Wmbl 0nwuXlc19M1on4FAySbHxdeNIjID4GPfFQMitEo1zhnttTei5hasiuh1gwC3uY9K/uTXWP jRFQ+/YQaVt8UrsWFYU0Wzoonzkbm+8fRkhiNO6Hc6MEuvKDLHMWdi5Er0kZZQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XccnM6dbFzkkd; Mon, 28 Oct 2024 15:31:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49SFVpP5088632; Mon, 28 Oct 2024 15:31:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49SFVpQB088629; Mon, 28 Oct 2024 15:31:51 GMT (envelope-from git) Date: Mon, 28 Oct 2024 15:31:51 GMT Message-Id: <202410281531.49SFVpQB088629@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Stefan =?utf-8?Q?E=C3=9Fer?= Subject: git: f35ccf46c7c6 - main - flua: lposix: add fnmatch function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f35ccf46c7c6cb7d26994ec5dc5926ea53be0116 Auto-Submitted: auto-generated The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=f35ccf46c7c6cb7d26994ec5dc5926ea53be0116 commit f35ccf46c7c6cb7d26994ec5dc5926ea53be0116 Author: Stefan Eßer AuthorDate: 2024-10-28 15:22:08 +0000 Commit: Stefan Eßer CommitDate: 2024-10-28 15:31:08 +0000 flua: lposix: add fnmatch function The fnmatch function matches a string against a shell-style filename pattern. It is a complex function and cannot easily be implenented using regular expressions. Adding fnmatch to flua increases the amd64 binary by less than 1 KB. Approved by: markj MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D46849 --- libexec/flua/linit_flua.c | 1 + libexec/flua/modules/lposix.c | 41 +++++++++++++++++++++++++++++++++++++++++ libexec/flua/modules/lposix.h | 1 + 3 files changed, 43 insertions(+) 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 #include +#include #include #include #include @@ -164,6 +165,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) { @@ -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 }, @@ -506,6 +529,24 @@ luaopen_posix_stdlib(lua_State *L) 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) { 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 +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);