From 27cc898f59e64579b51fae82a381c99566810e05 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 30 Nov 2022 00:02:38 +0000 Subject: [PATCH] adding getopt_long for unixes. --- libc-test/build.rs | 8 ++++++++ libc-test/semver/android.txt | 3 ++- libc-test/semver/apple.txt | 3 ++- libc-test/semver/dragonfly.txt | 1 + libc-test/semver/freebsd.txt | 1 + libc-test/semver/linux.txt | 1 + libc-test/semver/netbsd.txt | 1 + libc-test/semver/openbsd.txt | 3 ++- src/unix/bsd/mod.rs | 14 ++++++++++++++ src/unix/haiku/mod.rs | 15 ++++++++++++++- src/unix/linux_like/android/mod.rs | 14 ++++++++++++++ src/unix/linux_like/linux/mod.rs | 14 ++++++++++++++ src/unix/solarish/mod.rs | 15 +++++++++++++++ 13 files changed, 89 insertions(+), 4 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index a0e0380e61a96..f80a715dc1d23 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -199,6 +199,7 @@ fn test_apple(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "getopt.h", "glob.h", "grp.h", "iconv.h", @@ -421,6 +422,7 @@ fn test_openbsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "getopt.h", "libgen.h", "limits.h", "link.h", @@ -769,6 +771,7 @@ fn test_solarish(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "getopt.h", "glob.h", "grp.h", "ifaddrs.h", @@ -997,6 +1000,7 @@ fn test_netbsd(target: &str) { "elf.h", "errno.h", "fcntl.h", + "getopt.h", "libgen.h", "limits.h", "link.h", @@ -1208,6 +1212,7 @@ fn test_dragonflybsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "getopt.h", "glob.h", "grp.h", "ifaddrs.h", @@ -1511,6 +1516,7 @@ fn test_android(target: &str) { "elf.h", "errno.h", "fcntl.h", + "getopt.h", "grp.h", "ifaddrs.h", "libgen.h", @@ -1884,6 +1890,7 @@ fn test_freebsd(target: &str) { "errno.h", "execinfo.h", "fcntl.h", + "getopt.h", "glob.h", "grp.h", "iconv.h", @@ -2803,6 +2810,7 @@ fn test_linux(target: &str) { "dlfcn.h", "elf.h", "fcntl.h", + "getopt.h", "glob.h", [gnu]: "gnu/libc-version.h", "grp.h", diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 1e914ae4384b0..50979e5f81464 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -3026,6 +3026,7 @@ getline getlogin getnameinfo getopt +getopt_long getpeername getpgid getpgrp @@ -3594,4 +3595,4 @@ wmemchr write writev dirname -basename \ No newline at end of file +basename diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 95af36bbb41f7..329c8cdaac15b 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1895,6 +1895,7 @@ getline getloadavg getmntinfo getnameinfo +getopt_long getpeereid getpriority getprogname @@ -2228,4 +2229,4 @@ waitid xsw_usage xucred dirname -basename \ No newline at end of file +basename diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index f8f0fa08915a8..8d0172c112adf 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -1294,6 +1294,7 @@ getlastlogx getline getloadavg getnameinfo +getopt_long getpeereid getpriority getprogname diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 8f73e027afce0..f11e1c5cc3edc 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1599,6 +1599,7 @@ getline getloadavg getlocalbase getnameinfo +getopt_long getpagesize getpagesizes getpeereid diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 54825c24bc9ef..68bb3a0524d45 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2967,6 +2967,7 @@ getifaddrs getline getmntent getnameinfo +getopt_long getpriority getpwent getresgid diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index b650a456e8cf0..d6d519fd58ddb 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1254,6 +1254,7 @@ getlastlogx getline getloadavg getnameinfo +getopt_long getpeereid getpriority getprogname diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index d540671e1b037..0dcd2b40c8ae4 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -1040,6 +1040,7 @@ getline getloadavg getmntinfo getnameinfo +getopt_long getpeereid getpriority getprogname @@ -1232,4 +1233,4 @@ utrace wait4 xucred dirname -basename \ No newline at end of file +basename diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 50177015a924e..d49e3c44028c9 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -115,6 +115,13 @@ s! { pub rm_so: regoff_t, pub rm_eo: regoff_t, } + + pub struct option { + pub name: *const ::c_char, + pub has_arg: ::c_int, + pub flag: *mut ::c_int, + pub val: ::c_int, + } } s_no_extra_traits! { @@ -885,6 +892,13 @@ extern "C" { pub fn srand48(seed: ::c_long); pub fn seed48(xseed: *mut ::c_ushort) -> *mut ::c_ushort; pub fn lcong48(p: *mut ::c_ushort); + pub fn getopt_long( + argc: ::c_int, + argv: *const *mut c_char, + optstring: *const c_char, + longopts: *const option, + longindex: *mut ::c_int, + ) -> ::c_int; } cfg_if! { diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index bb2e0351bf2cb..005b1d9df5c56 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -430,6 +430,13 @@ s! { pub key: *mut ::c_char, pub data: *mut ::c_void, } + + pub struct option { + pub name: *const ::c_char, + pub has_arg: ::c_int, + pub flag: *mut ::c_int, + pub val: ::c_int, + } } s_no_extra_traits! { @@ -1971,7 +1978,13 @@ extern "C" { attr: *mut posix_spawnattr_t, sigmask: *const ::sigset_t, ) -> ::c_int; - + pub fn getopt_long( + argc: ::c_int, + argv: *const *mut c_char, + optstring: *const c_char, + longopts: *const option, + longindex: *mut ::c_int, + ) -> ::c_int; } #[link(name = "bsd")] diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 4c3dd4c88cb1a..61885582aa0db 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -482,6 +482,13 @@ s! { pub code: ::__u16, pub absinfo: input_absinfo, } + + pub struct option { + pub name: *const ::c_char, + pub has_arg: ::c_int, + pub flag: *mut ::c_int, + pub val: ::c_int, + } } s_no_extra_traits! { @@ -3471,6 +3478,13 @@ extern "C" { pub fn dirname(path: *const ::c_char) -> *mut ::c_char; pub fn basename(path: *const ::c_char) -> *mut ::c_char; + pub fn getopt_long( + argc: ::c_int, + argv: *const *mut c_char, + optstring: *const c_char, + longopts: *const option, + longindex: *mut ::c_int, + ) -> ::c_int; } cfg_if! { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 6faf3ae04e452..f0a0820c3d3fc 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -618,6 +618,13 @@ s! { pub ifr6_prefixlen: u32, pub ifr6_ifindex: ::c_int, } + + pub struct option { + pub name: *const ::c_char, + pub has_arg: ::c_int, + pub flag: *mut ::c_int, + pub val: ::c_int, + } } s_no_extra_traits! { @@ -4441,6 +4448,13 @@ extern "C" { pub fn pthread_getname_np(thread: ::pthread_t, name: *mut ::c_char, len: ::size_t) -> ::c_int; pub fn pthread_setname_np(thread: ::pthread_t, name: *const ::c_char) -> ::c_int; + pub fn getopt_long( + argc: ::c_int, + argv: *const *mut c_char, + optstring: *const c_char, + longopts: *const option, + longindex: *mut ::c_int, + ) -> ::c_int; } cfg_if! { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 6b0557d359c9e..abe304e8ea52b 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -466,6 +466,13 @@ s! { pub pi_fputypes: [::c_char; PI_FPUTYPE as usize], pub pi_clock: ::c_int, } + + pub struct option { + pub name: *const ::c_char, + pub has_arg: ::c_int, + pub flag: *mut ::c_int, + pub val: ::c_int, + } } s_no_extra_traits! { @@ -3182,6 +3189,14 @@ extern "C" { pub fn backtrace(buffer: *mut *mut ::c_void, size: ::c_int) -> ::c_int; pub fn backtrace_symbols(buffer: *const *mut ::c_void, size: ::c_int) -> *mut *mut ::c_char; pub fn backtrace_symbols_fd(buffer: *const *mut ::c_void, size: ::c_int, fd: ::c_int); + + pub fn getopt_long( + argc: ::c_int, + argv: *const *mut c_char, + optstring: *const c_char, + longopts: *const option, + longindex: *mut ::c_int, + ) -> ::c_int; } #[link(name = "sendfile")]