add trivial examples
This commit is contained in:
Generated
+16
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.186"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||
|
||||
[[package]]
|
||||
name = "libc_test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "libc_test"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.186"
|
||||
@@ -0,0 +1,15 @@
|
||||
extern crate libc;
|
||||
|
||||
use std::ffi::CStr;
|
||||
fn main() {
|
||||
unsafe {
|
||||
let buf: *mut libc::utsname = libc::malloc(size_of::<libc::utsname>()) as *mut libc::utsname;
|
||||
if buf.is_null() {
|
||||
panic!("failed to allocate buf");
|
||||
}
|
||||
libc::uname(buf);
|
||||
let sysname: &CStr = CStr::from_ptr((*buf).sysname.as_ptr());
|
||||
println!("Hello, {}!", sysname.to_str().unwrap());
|
||||
libc::free(buf as *mut core::ffi::c_void);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user