1 #![unstable(reason = "not public", issue = "none", feature = "fd")]
3 use crate::io
::{self, Read, ReadBuf}
;
6 use crate::sys
::hermit
::abi
;
7 use crate::sys
::unsupported
;
8 use crate::sys_common
::AsInner
;
16 pub fn new(fd
: i32) -> FileDesc
{
20 pub fn raw(&self) -> i32 {
24 /// Extracts the actual file descriptor without closing it.
25 pub fn into_raw(self) -> i32 {
31 pub fn read(&self, buf
: &mut [u8]) -> io
::Result
<usize> {
32 let result
= unsafe { abi::read(self.fd, buf.as_mut_ptr(), buf.len()) }
;
36 pub fn read_to_end(&self, buf
: &mut Vec
<u8>) -> io
::Result
<usize> {
38 (&mut me
).read_to_end(buf
)
41 pub fn write(&self, buf
: &[u8]) -> io
::Result
<usize> {
42 let result
= unsafe { abi::write(self.fd, buf.as_ptr(), buf.len()) }
;
46 pub fn duplicate(&self) -> io
::Result
<FileDesc
> {
47 self.duplicate_path(&[])
49 pub fn duplicate_path(&self, _path
: &[u8]) -> io
::Result
<FileDesc
> {
53 pub fn nonblocking(&self) -> io
::Result
<bool
> {
57 pub fn set_cloexec(&self) -> io
::Result
<()> {
61 pub fn set_nonblocking(&self, _nonblocking
: bool
) -> io
::Result
<()> {
66 impl<'a
> Read
for &'a FileDesc
{
67 fn read(&mut self, buf
: &mut [u8]) -> io
::Result
<usize> {
72 impl AsInner
<i32> for FileDesc
{
73 fn as_inner(&self) -> &i32 {
78 impl Drop
for FileDesc
{
80 // Note that errors are ignored when closing a file descriptor. The
81 // reason for this is that if an error occurs we don't actually know if
82 // the file descriptor was closed or not, and if we retried (for
83 // something like EINTR), we might close another valid file descriptor
84 // (opened after we closed ours.
85 let _
= unsafe { abi::close(self.fd) }
;