Skip to content
Snippets Groups Projects
Commit 16c51a29 authored by stratact's avatar stratact
Browse files

Use the right C types from `platform::types`

parent b389e483
No related branches found
No related tags found
1 merge request!127Update `platform::rawfile`
use core::ops::Deref; use core::ops::Deref;
use super::{open, dup, close}; use super::{open, dup, close, types::*};
pub struct RawFile(usize); trait Into<c_char> {
into(self) -> c_char;
}
pub struct RawFile(c_int);
impl RawFile { impl RawFile {
pub fn open<T: AsRef<[u8]>>(path: T, flags: usize, mode: usize) -> Result<RawFile, ()> { pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> Result<RawFile, ()> {
match open(path.as_ref()[0] as *const i8, flags as i32, mode as u16) { match open(path, oflag, mode) {
-1 => Err(()), -1 => Err(()),
n => Ok(RawFile(n as usize)) n => Ok(RawFile(n))
} }
} }
pub fn dup(&self, _buf: &[u8]) -> Result<RawFile, ()> { pub fn dup(&self, _buf: &[u8]) -> Result<RawFile, ()> {
match dup(self.0 as i32) { match dup(self.0) {
-1 => Err(()), -1 => Err(()),
n => Ok(RawFile(n as usize)) n => Ok(RawFile(n))
} }
} }
pub fn as_raw_fd(&self) -> usize { pub fn as_raw_fd(&self) -> c_int {
self.0 self.0
} }
pub fn into_raw_fd(self) -> usize { pub fn into_raw_fd(self) -> c_int {
self.0 self.0
} }
pub fn from_raw_fd(fd: usize) -> Self { pub fn from_raw_fd(fd: c_int) -> Self {
RawFile(fd) RawFile(fd)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment