Module fs

Source
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

Functions§

mkdir
Create directories recursively
remove
Remove a file