getopt.rs(3): formatting

This commit is contained in:
Emma Tebibyte 2024-04-11 23:51:52 -06:00
parent ad92fe27d4
commit 95927ba8c5
Signed by: emma
GPG Key ID: 06FA419A1698C270
1 changed files with 6 additions and 5 deletions

View File

@ -29,7 +29,7 @@ pub enum OptError {
UnknownOpt,
}
// Function signature
/* function signature */
pub trait GetOpt {
fn getopt(&self, optstring: &str) -> Option<Result<Opt, OptError>>;
}
@ -43,10 +43,11 @@ impl GetOpt for Vec<String> {
.map(Result::unwrap)
.collect();
/* these operations must be separated out into separate operations so
* the CStrings can live long enough */
let argv: Vec<_> = c_strings.iter().map(|x| x.as_ptr()).collect();
let argv_ptr = argv.as_ptr() as *const *mut c_char;
let optstring_c = CString::new(optstring).unwrap();
let opts = optstring_c.into_raw();
let opts = CString::new(optstring).unwrap().into_raw();
let len = self.len() as c_int;
unsafe {
@ -67,10 +68,10 @@ impl GetOpt for Vec<String> {
*
* Otherwise, getopt() shall return -1 when all command line
* options are parsed. */
58 => { /* ASCII value for ':' */
58 => { /* numerical ASCII value for ':' */
return Some(Err(OptError::MissingArg));
},
63 => { /* ASCII value for '?' */
63 => { /* numerical ASCII value for '?' */
return Some(Err(OptError::UnknownOpt))
},
/* From getopt(3p):