From 1b2232978fb15321e6f4232889e1c2be9bd1ba9b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 20 Sep 2024 11:59:55 +0300 Subject: [PATCH] Add fnmatch.h Add fnmatch() function and FNM_* constants. Documentation: Header file: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fnmatch.h.html fnmatch() function: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fnmatch.html Signed-off-by: Manos Pitsidianakis (backport ) (cherry picked from commit 70de2da72a5ed176628e9d93408d5f7b95230db6) --- libc-test/build.rs | 12 ++++++++++++ libc-test/semver/unix.txt | 6 ++++++ src/unix/mod.rs | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index dfa6185195dbc..844a458fcd5a0 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -205,6 +205,7 @@ fn test_apple(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -482,6 +483,7 @@ fn test_openbsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "libgen.h", "limits.h", @@ -793,6 +795,7 @@ fn test_redox(target: &str) { "dlfcn.h", "errno.h", "fcntl.h", + "fnmatch.h", "grp.h", "limits.h", "locale.h", @@ -852,6 +855,7 @@ fn test_solarish(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -1092,6 +1096,7 @@ fn test_netbsd(target: &str) { "elf.h", "errno.h", "fcntl.h", + "fnmatch.h", "getopt.h", "libgen.h", "limits.h", @@ -1308,6 +1313,7 @@ fn test_dragonflybsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -1531,6 +1537,7 @@ fn test_wasi(target: &str) { "dirent.h", "errno.h", "fcntl.h", + "fnmatch.h", "langinfo.h", "limits.h", "locale.h", @@ -1646,6 +1653,7 @@ fn test_android(target: &str) { "elf.h", "errno.h", "fcntl.h", + "fnmatch.h", "getopt.h", "grp.h", "ifaddrs.h", @@ -2145,6 +2153,7 @@ fn test_freebsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -2762,6 +2771,7 @@ fn test_emscripten(target: &str) { "dlfcn.h", "errno.h", "fcntl.h", + "fnmatch.h", "glob.h", "grp.h", "ifaddrs.h", @@ -3030,6 +3040,7 @@ fn test_neutrino(target: &str) { "dlfcn.h", "sys/elf.h", "fcntl.h", + "fnmatch.h", "glob.h", "grp.h", "iconv.h", @@ -3427,6 +3438,7 @@ fn test_linux(target: &str) { "dlfcn.h", "elf.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", [gnu]: "gnu/libc-version.h", diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index bb8e319def299..1ada0edd77b5d 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -132,6 +132,11 @@ FD_ZERO FILE FIOCLEX FIONBIO +FNM_CASEFOLD +FNM_NOESCAPE +FNM_NOMATCH +FNM_PATHNAME +FNM_PERIOD F_DUPFD F_DUPFD_CLOEXEC F_GETFD @@ -525,6 +530,7 @@ fgetpos fgets fileno flock +fnmatch fopen fork fpathconf diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 3f1148043f532..6495a348d9d28 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -313,6 +313,24 @@ pub const ATF_PERM: ::c_int = 0x04; pub const ATF_PUBL: ::c_int = 0x08; pub const ATF_USETRAILERS: ::c_int = 0x10; +pub const FNM_PERIOD: c_int = 1 << 2; +pub const FNM_CASEFOLD: c_int = 1 << 4; +pub const FNM_NOMATCH: c_int = 1; + +cfg_if! { + if #[cfg(any( + target_os = "macos", + target_os = "freebsd", + target_os = "android", + ))] { + pub const FNM_PATHNAME: c_int = 1 << 1; + pub const FNM_NOESCAPE: c_int = 1 << 0; + } else { + pub const FNM_PATHNAME: c_int = 1 << 0; + pub const FNM_NOESCAPE: c_int = 1 << 1; + } +} + extern "C" { pub static in6addr_loopback: in6_addr; pub static in6addr_any: in6_addr; @@ -1580,6 +1598,10 @@ cfg_if! { } } +extern "C" { + pub fn fnmatch(pattern: *const c_char, name: *const c_char, flags: c_int) -> c_int; +} + cfg_if! { if #[cfg(target_env = "newlib")] { mod newlib;