Newtype file descriptors.

To avoid various bugs regarding the typing of file descriptors, we
newtype them into a simple wrapper type.

- Document some stuff.
This commit is contained in:
ticki 2016-08-29 11:58:31 +02:00
parent 3a232cc60f
commit 94a1a0fa0c
3 changed files with 24 additions and 11 deletions

View file

@ -1,7 +1,7 @@
use core::str;
use syscall::Result;
use super::Scheme;
use super::{Scheme, Fd};
pub struct DebugScheme;
@ -14,21 +14,21 @@ impl Scheme for DebugScheme {
/// Read the file `number` into the `buffer`
///
/// Returns the number of bytes read
fn read(&mut self, _file: usize, _buffer: &mut [u8]) -> Result<usize> {
fn read(&mut self, _file: Fd, _buffer: &mut [u8]) -> Result<usize> {
Ok(0)
}
/// Write the `buffer` to the `file`
///
/// Returns the number of bytes written
fn write(&mut self, _file: usize, buffer: &[u8]) -> Result<usize> {
fn write(&mut self, _file: Fd, buffer: &[u8]) -> Result<usize> {
//TODO: Write bytes, do not convert to str
print!("{}", unsafe { str::from_utf8_unchecked(buffer) });
Ok(buffer.len())
}
/// Close the file `number`
fn close(&mut self, _file: usize) -> Result<()> {
fn close(&mut self, _file: Fd) -> Result<()> {
Ok(())
}
}