getopt.rs(3): better Opt return

This commit is contained in:
Emma Tebibyte 2024-04-13 23:42:11 -06:00
parent d1b77d652b
commit 78eacd660a
Signed by: emma
GPG Key ID: 06FA419A1698C270
1 changed files with 5 additions and 6 deletions

View File

@ -21,7 +21,6 @@ use std::ffi::{ c_int, c_char, CString, CStr };
pub struct Opt {
pub arg: Option<String>,
pub ind: i32,
/* opt is set to either the current option or the one that cause an error */
pub opt: String,
}
@ -51,8 +50,8 @@ impl GetOpt for Vec<String> {
let opts = CString::new(optstring).unwrap().into_raw();
let len = self.len() as c_int;
unsafe {
match getopt(len, argv_ptr, opts) {
unsafe { // TODO: enable optind modification
match getopt(len, argv_ptr, opts) {
/* From getopt(3p):
*
* The getopt() function shall return the next option character
@ -95,9 +94,9 @@ impl GetOpt for Vec<String> {
.into_owned();
Some(Ok(Opt {
arg: Some(arg),
ind: optind,
opt: opt.to_string(),
arg: Some(arg), /* opt argument */
ind: optind, /* opt index */
opt: opt.to_string(), /* option itself */
}))
},
}