1 #![unstable(reason = "not public", issue = "0", feature = "fd")]
3 use crate::io
::{self, ErrorKind, Read}
;
6 use crate::sys
::hermit
::abi
;
7 use crate::sys_common
::AsInner
;
15 pub fn new(fd
: i32) -> FileDesc
{
19 pub fn raw(&self) -> i32 {
23 /// Extracts the actual file descriptor without closing it.
24 pub fn into_raw(self) -> i32 {
30 pub fn read(&self, buf
: &mut [u8]) -> io
::Result
<usize> {
31 let result
= unsafe { abi::read(self.fd, buf.as_mut_ptr(), buf.len()) }
;
35 pub fn read_to_end(&self, buf
: &mut Vec
<u8>) -> io
::Result
<usize> {
37 (&mut me
).read_to_end(buf
)
40 pub fn write(&self, buf
: &[u8]) -> io
::Result
<usize> {
41 let result
= unsafe { abi::write(self.fd, buf.as_ptr(), buf.len()) }
;
45 pub fn duplicate(&self) -> io
::Result
<FileDesc
> {
46 self.duplicate_path(&[])
48 pub fn duplicate_path(&self, _path
: &[u8]) -> io
::Result
<FileDesc
> {
49 Err(io
::Error
::new(ErrorKind
::Other
, "duplicate isn't supported"))
52 pub fn nonblocking(&self) -> io
::Result
<bool
> {
56 pub fn set_cloexec(&self) -> io
::Result
<()> {
57 Err(io
::Error
::new(ErrorKind
::Other
, "cloexec isn't supported"))
60 pub fn set_nonblocking(&self, _nonblocking
: bool
) -> io
::Result
<()> {
61 Err(io
::Error
::new(ErrorKind
::Other
, "nonblocking isn't supported"))
65 impl<'a
> Read
for &'a FileDesc
{
66 fn read(&mut self, buf
: &mut [u8]) -> io
::Result
<usize> {
71 impl AsInner
<i32> for FileDesc
{
72 fn as_inner(&self) -> &i32 {
77 impl Drop
for FileDesc
{
79 // Note that errors are ignored when closing a file descriptor. The
80 // reason for this is that if an error occurs we don't actually know if
81 // the file descriptor was closed or not, and if we retried (for
82 // something like EINTR), we might close another valid file descriptor
83 // (opened after we closed ours.
84 let _
= unsafe { abi::close(self.fd) }
;