Skip to main content

relibc/header/unistd/
getopt.rs

1//! `getopt` implementation.
2//!
3//! See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
4
5use core::ptr;
6
7use crate::{
8    header::getopt,
9    platform::types::{c_char, c_int},
10};
11
12/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
13#[allow(non_upper_case_globals)]
14#[unsafe(no_mangle)]
15pub static mut optarg: *mut c_char = ptr::null_mut();
16
17/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
18#[allow(non_upper_case_globals)]
19#[unsafe(no_mangle)]
20pub static mut opterr: c_int = 1;
21
22/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
23#[allow(non_upper_case_globals)]
24#[unsafe(no_mangle)]
25pub static mut optind: c_int = 1;
26
27/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
28#[allow(non_upper_case_globals)]
29#[unsafe(no_mangle)]
30pub static mut optopt: c_int = -1;
31
32/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getopt.html>.
33#[unsafe(no_mangle)]
34pub unsafe extern "C" fn getopt(
35    argc: c_int,
36    argv: *const *mut c_char,
37    optstring: *const c_char,
38) -> c_int {
39    unsafe { getopt::getopt_long(argc, argv, optstring, ptr::null(), ptr::null_mut()) }
40}