Expand description
The intuitive file system module
Demo of the intuitive File, call methods like C API convention, check the returned integer for status, 0 means success, negative value means error.
use wsd::fs::*;
fn test() -> i32 {
let mut f = File::new();
if f.open("test.txt", O_CREATE | O_RW) != 0 {
// check the error
println!("Error: {}", f.error());
return -1;
}
let data = "Hello World!";
let n = f.write(data);
if n < 0 {
// write error
}
f.rewind();
let mut buf = [0; 4096];
let n = f.read(&mut buf);
if n > 0 {
// success to read n bytes
}
f.seek(256, SEEK_SET);
f.write("more data");
f.close();
return 0;
}
Structs§
- File
- Intuitive File
Constants§
- O_
APPEND - Append only
- O_
CREATE - Create and open the file
- O_
NONBLOCK - Non blocking to
File::write
- O_READ
- Read only
- O_RW
- Read and write
- O_
TRUNCATE - Causes the file to be truncated if it exists
- O_WRITE
- Write only
- SEEK_
CUR - Seek to relative position from current
- SEEK_
END - Seek to relative position from end
- SEEK_
SET - Seek to absolute position