fn open(path: &str, oflag: i32) -> i32 {  //  `&str` is a reference to a string slice, similar to `const char *` in C

    use crate::open;

    //  Convert `str` to `String`, which similar to `char [64]` in C
    let mut s_with_null = String::from_str(path)  //  `mut` because we will modify it
        .expect("open conversion failed");        //  If it exceeds 64 chars, halt with an error
    
    //  Terminate the string with null, since we will be passing to C
    s_with_null.push('\0')
        .expect("open overflow");  //  If we exceed 64 chars, halt with an error

    //  Convert the null-terminated string to a pointer
    let p = s_with_null.as_str().as_ptr();

    //  Call the C function
    unsafe {  //  Flag this code as unsafe because we're calling a C function
        open(p, oflag)
    }

    //  No semicolon `;` here, so the value returned by the C function will be passed to our caller
}
/// Open a file and return the file descriptor.
/// TODO: Auto-generate this wrapper with `bindgen` from the C declaration
Open a file and return the file descriptor.
TODO: Auto-generate this wrapper with `bindgen` from the C declaration
Open a file and return the file descriptor . TODO : Auto - generate this wrapper with ` bindgen ` from the C declaration
fn open(path: &str, oflag: i32) -> i32 {  //  `&str` is a reference to a string slice, similar to `const char *` in C
    use crate::open;
    //  Convert `str` to `String`, which similar to `char [64]` in C
    let mut s_with_null = String::from_str(path)  //  `mut` because we will modify it
        .expect("open conversion failed");        //  If it exceeds 64 chars, halt with an error
    //  Terminate the string with null, since we will be passing to C
    s_with_null.push('\0')
        .expect("open overflow");  //  If we exceed 64 chars, halt with an error
    //  Convert the null-terminated string to a pointer
    let p = s_with_null.as_str().as_ptr();
    //  Call the C function
    unsafe {  //  Flag this code as unsafe because we're calling a C function
        open(p, oflag)
    }
    //  No semicolon `;` here, so the value returned by the C function will be passed to our caller
}
fn open ( path : & str , oflag : i32 ) -> i32 { //  `&str` is a reference to a string slice, similar to `const char *` in C use crate :: open ; //  Convert `str` to `String`, which similar to `char [64]` in C let mut s_with_null = String :: from_str ( path ) //  `mut` because we will modify it . expect ( " " ) ; //  If it exceeds 64 chars, halt with an error //  Terminate the string with null, since we will be passing to C s_with_null . push ( '\0' ) . expect ( " " ) ; //  If we exceed 64 chars, halt with an error //  Convert the null-terminated string to a pointer let p = s_with_null . as_str ( ) . as_ptr ( ) ; //  Call the C function unsafe { //  Flag this code as unsafe because we're calling a C function open ( p , oflag ) } //  No semicolon `;` here, so the value returned by the C function will be passed to our caller }
Open a file and return the file descriptor.
Open a file and return the file descriptor .
path
&str
oflag
i32
path
&str
oflag
i32