From 6c55043e844da0d88243058ddcea507d345469eb 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. Signed-off-by: Manos Pitsidianakis --- libc-test/build.rs | 12 ++++++++++++ src/unix/mod.rs | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 938294717eee3..0ea0abb7f915f 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -191,6 +191,7 @@ fn test_apple(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -454,6 +455,7 @@ fn test_openbsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "libgen.h", "limits.h", @@ -731,6 +733,7 @@ fn test_redox(target: &str) { "dlfcn.h", "errno.h", "fcntl.h", + "fnmatch.h", "grp.h", "limits.h", "locale.h", @@ -790,6 +793,7 @@ fn test_solarish(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -1030,6 +1034,7 @@ fn test_netbsd(target: &str) { "elf.h", "errno.h", "fcntl.h", + "fnmatch.h", "getopt.h", "libgen.h", "limits.h", @@ -1244,6 +1249,7 @@ fn test_dragonflybsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -1464,6 +1470,7 @@ fn test_wasi(target: &str) { "dirent.h", "errno.h", "fcntl.h", + "fnmatch.h", "langinfo.h", "limits.h", "locale.h", @@ -1579,6 +1586,7 @@ fn test_android(target: &str) { "elf.h", "errno.h", "fcntl.h", + "fnmatch.h", "getopt.h", "grp.h", "ifaddrs.h", @@ -2087,6 +2095,7 @@ fn test_freebsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "fnmatch.h", "getopt.h", "glob.h", "grp.h", @@ -2706,6 +2715,7 @@ fn test_emscripten(target: &str) { "dlfcn.h", "errno.h", "fcntl.h", + "fnmatch.h", "glob.h", "grp.h", "ifaddrs.h", @@ -2974,6 +2984,7 @@ fn test_neutrino(target: &str) { "dlfcn.h", "sys/elf.h", "fcntl.h", + "fnmatch.h", "glob.h", "grp.h", "iconv.h", @@ -3368,6 +3379,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/src/unix/mod.rs b/src/unix/mod.rs index 1e6daface673a..aac5055f33a30 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -320,6 +320,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; @@ -1570,6 +1588,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;