From nobody Fri Aug 29 15:05:07 2025 X-Original-To: dev-commits-src-all@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 4cD1lm32M0z65gmG; Fri, 29 Aug 2025 15:05:08 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cD1ll61Bvz3txd; Fri, 29 Aug 2025 15:05:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756479907; 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=b1P0RwX5jPuaZn//f3iq1bURcV6NMYb8zgQwZ7PZjJY=; b=gco1UuP10zMBLmdl4VG/F/dwoNzxmpglihYRW5AKKVpb02S3oIdHkIEkxNPlAOY9An2f3x BxZdKfWmKT55t0YLGdZFBM812oB4lbJz8oluQRjLdF5c9GmoOcVwSdR4zTUnppcHyR9rm8 iJ0QhY8XPglJ64x7j4h/ddA1+RZYvrmPWaN92JqgA+oSd6iBtuTuEnrfiWp9W/wQCnID8H Xors/U9/ym2/ob0pFiO9hHSLJNkBoE9yVn+jGBV96/eg6ZC+Cuqm7+vVPu7Pi6A3AaOQFC GONjwCfki4dxMfTXEQWUqRa7DKw/8BN5Ox4jrcSouFd7BBVM5j7C8+x0WlsPFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756479907; 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=b1P0RwX5jPuaZn//f3iq1bURcV6NMYb8zgQwZ7PZjJY=; b=RaeqC0ZA4EVvzSTzOLThZ8bbBtBMmgdfkLtW5tXoUWnCSf15OmeAw/JDJ/WNWoNCCcp3Pg 1ZhMCrHyLPo+j7PHmGqBbnaieal7yS5R5UOa32RGm3el/8Kte1JWdVka7TadkP5ZbgsEHj mD04LMvwmxpu7F4d7Wqz9DFLu3DqRSk9DSXQtGZlxuxTdEWicPfJiMf0y1BUDqgl1V2xuz HvYEJuYACMumk+E5DPAHdkay1vHwUnc+W5zdnF02Gf0NG/7QnEw36WGVXNlSnWSAbEvo7N f88r8oxkYsuoa5AwZtxHgp2I/8F1kGEZvsOtwks5IPMt8qbDGI6+Kwt2PdAtLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756479907; a=rsa-sha256; cv=none; b=IrooHvWLdZHAjuLKE5pShCjjBgwtbyQU//MZol+RZ09DRZ51WGQBl4nw2nEmvjr+FgzDOw tVj3MSWX9ywTiChbcPO0/6OSpsYjIjiQ5mLyFF1BRtOVEPmCuZq5Bk6hlTYrIDAtrzcLN6 1HKXYX8rCEgcGLbSVBUqOdpkGBuqVuV2ZrEOF7Enowh0IylG8/G3EXQ0O6lFWBTCX3NQ9f sZwT5RPhqFr1f40NbZMDTZofoLa3LcDrd346X6dy2jkofIGgldIr1/p+OVgc7IFIYpnbAo 0YeNZAdyegO21N0FFft3vIoEIWvw9gaIpt/zqvL6ZTn4KlEylqH9tZzvwdKgWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cD1ll5Xyvzlnk; Fri, 29 Aug 2025 15:05:07 +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 57TF5743080564; Fri, 29 Aug 2025 15:05:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57TF57Fh080561; Fri, 29 Aug 2025 15:05:07 GMT (envelope-from git) Date: Fri, 29 Aug 2025 15:05:07 GMT Message-Id: <202508291505.57TF57Fh080561@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: d52dc0b4bf6c - stable/14 - flua: lposix: add fnmatch function List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d52dc0b4bf6c2fb34b4a9ab614247b7c5524ff32 Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=d52dc0b4bf6c2fb34b4a9ab614247b7c5524ff32 commit d52dc0b4bf6c2fb34b4a9ab614247b7c5524ff32 Author: Stefan Eßer AuthorDate: 2024-10-28 15:22:08 +0000 Commit: Ed Maste CommitDate: 2025-08-29 14:57:36 +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 (cherry picked from commit f35ccf46c7c6cb7d26994ec5dc5926ea53be0116) --- 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 13c2c7fcc52f..9d712066485a 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -56,6 +56,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 4422d54917e1..2e8e9bfc389e 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -173,6 +174,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) { @@ -471,6 +489,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 }, @@ -515,6 +538,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);