add trivial examples

This commit is contained in:
mae
2026-07-13 07:25:54 -05:00
parent d6cef19507
commit 9d4c3e911e
16 changed files with 258 additions and 0 deletions
+16
View File
@@ -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",
]
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "libc_test"
version = "0.1.0"
edition = "2024"
[dependencies]
libc = "0.2.186"
+15
View File
@@ -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);
}
}