-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
confused by libc::stat #403
Comments
Rust has separate namespaces for types (where stat struct would be) and values Those two can be use as follows (to display inode number of root directory, in extern crate libc;
use std::mem;
use std::ffi::*;
fn main() {
unsafe {
let mut s: libc::stat = mem::zeroed();
let path = CString::new("/").unwrap();
let ret = libc::stat(path.as_ptr(), &mut s);
assert_eq!(ret, 0);
println!("{:?}", s.st_ino);
}
} If this actually causes problems, it will be easier to help if you actually |
I managed, I had a stupid syntax error, totally my fault. Still, wouldn't it be nice to add this example in the documentation? I think it could help other people |
Thanks for the report! Rust actually has two namespaces (a type and a value namespace) for problems like this, so depending on where Currently this library has little documentation as it's just a straight binding to libc, but perhaps a clarification could be made in the book somewhere? |
I'm trying to call the stat function for a personal project. As far as I understood I need to call the
libc::stat
function on thelibc::stat
struct. I can understand how it works, but since struct and function are in the same module, the rust compiler is quite confused.I've searched online and found nothing that tells me how to
use libc::<stat as struct>
or<stat as fn>(path, &mut stat_struct)
or similar combinations.How am I supposed to fix this? Is this a bug in the library? Or is it me that is missing something about the language?
The text was updated successfully, but these errors were encountered: