rust/src/libstd/sys/sgx/fd.rs
David Tolnay c34fbfaad3
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd/sys -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd/sys outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of the files.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:37:58 -08:00

74 lines
1.5 KiB
Rust

use fortanix_sgx_abi::Fd;
use super::abi::usercalls;
use crate::io::{self, IoSlice, IoSliceMut};
use crate::mem;
use crate::sys::{AsInner, FromInner, IntoInner};
#[derive(Debug)]
pub struct FileDesc {
fd: Fd,
}
impl FileDesc {
pub fn new(fd: Fd) -> FileDesc {
FileDesc { fd: fd }
}
pub fn raw(&self) -> Fd {
self.fd
}
/// Extracts the actual filedescriptor without closing it.
pub fn into_raw(self) -> Fd {
let fd = self.fd;
mem::forget(self);
fd
}
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
usercalls::read(self.fd, &mut [IoSliceMut::new(buf)])
}
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
usercalls::read(self.fd, bufs)
}
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
usercalls::write(self.fd, &[IoSlice::new(buf)])
}
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
usercalls::write(self.fd, bufs)
}
pub fn flush(&self) -> io::Result<()> {
usercalls::flush(self.fd)
}
}
impl AsInner<Fd> for FileDesc {
fn as_inner(&self) -> &Fd {
&self.fd
}
}
impl IntoInner<Fd> for FileDesc {
fn into_inner(self) -> Fd {
let fd = self.fd;
mem::forget(self);
fd
}
}
impl FromInner<Fd> for FileDesc {
fn from_inner(fd: Fd) -> FileDesc {
FileDesc { fd }
}
}
impl Drop for FileDesc {
fn drop(&mut self) {
usercalls::close(self.fd)
}
}