]>
git.proxmox.com Git - rustc.git/blob - vendor/rustix/src/io/read_write.rs
1 //! `read` and `write`, optionally positioned, optionally vectored
3 use crate::{backend, io}
;
6 // Declare `IoSlice` and `IoSliceMut`.
8 #[cfg(not(feature = "std"))]
9 pub use backend
::io
::io_slice
::{IoSlice, IoSliceMut}
;
11 #[cfg(feature = "std")]
12 pub use std
::io
::{IoSlice, IoSliceMut}
;
14 /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
15 #[cfg(any(target_os = "android", target_os = "linux"))]
16 pub use backend
::io
::types
::ReadWriteFlags
;
18 /// `read(fd, buf)`—Reads from a stream.
25 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
26 /// [Linux]: https://man7.org/linux/man-pages/man2/read.2.html
27 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/read.2.html
29 pub fn read
<Fd
: AsFd
>(fd
: Fd
, buf
: &mut [u8]) -> io
::Result
<usize> {
30 backend
::io
::syscalls
::read(fd
.as_fd(), buf
)
33 /// `write(fd, buf)`—Writes to a stream.
40 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
41 /// [Linux]: https://man7.org/linux/man-pages/man2/write.2.html
42 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/write.2.html
44 pub fn write
<Fd
: AsFd
>(fd
: Fd
, buf
: &[u8]) -> io
::Result
<usize> {
45 backend
::io
::syscalls
::write(fd
.as_fd(), buf
)
48 /// `pread(fd, buf, offset)`—Reads from a file at a given position.
55 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html
56 /// [Linux]: https://man7.org/linux/man-pages/man2/pread.2.html
57 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pread.2.html
59 pub fn pread
<Fd
: AsFd
>(fd
: Fd
, buf
: &mut [u8], offset
: u64) -> io
::Result
<usize> {
60 backend
::io
::syscalls
::pread(fd
.as_fd(), buf
, offset
)
63 /// `pwrite(fd, bufs)`—Writes to a file at a given position.
70 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html
71 /// [Linux]: https://man7.org/linux/man-pages/man2/pwrite.2.html
72 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pwrite.2.html
74 pub fn pwrite
<Fd
: AsFd
>(fd
: Fd
, buf
: &[u8], offset
: u64) -> io
::Result
<usize> {
75 backend
::io
::syscalls
::pwrite(fd
.as_fd(), buf
, offset
)
78 /// `readv(fd, bufs)`—Reads from a stream into multiple buffers.
85 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html
86 /// [Linux]: https://man7.org/linux/man-pages/man2/readv.2.html
87 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/readv.2.html
89 pub fn readv
<Fd
: AsFd
>(fd
: Fd
, bufs
: &mut [IoSliceMut
<'_
>]) -> io
::Result
<usize> {
90 backend
::io
::syscalls
::readv(fd
.as_fd(), bufs
)
93 /// `writev(fd, bufs)`—Writes to a stream from multiple buffers.
100 /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html
101 /// [Linux]: https://man7.org/linux/man-pages/man2/writev.2.html
102 /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/writev.2.html
104 pub fn writev
<Fd
: AsFd
>(fd
: Fd
, bufs
: &[IoSlice
<'_
>]) -> io
::Result
<usize> {
105 backend
::io
::syscalls
::writev(fd
.as_fd(), bufs
)
108 /// `preadv(fd, bufs, offset)`—Reads from a file at a given position into
109 /// multiple buffers.
114 /// [Linux]: https://man7.org/linux/man-pages/man2/preadv.2.html
115 #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))]
117 pub fn preadv
<Fd
: AsFd
>(fd
: Fd
, bufs
: &mut [IoSliceMut
<'_
>], offset
: u64) -> io
::Result
<usize> {
118 backend
::io
::syscalls
::preadv(fd
.as_fd(), bufs
, offset
)
121 /// `pwritev(fd, bufs, offset)`—Writes to a file at a given position from
122 /// multiple buffers.
127 /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev.2.html
128 #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))]
130 pub fn pwritev
<Fd
: AsFd
>(fd
: Fd
, bufs
: &[IoSlice
<'_
>], offset
: u64) -> io
::Result
<usize> {
131 backend
::io
::syscalls
::pwritev(fd
.as_fd(), bufs
, offset
)
134 /// `preadv2(fd, bufs, offset, flags)`—Reads data, with several options.
136 /// An `offset` of `u64::MAX` means to use and update the current file offset.
141 /// [Linux]: https://man7.org/linux/man-pages/man2/preadv2.2.html
142 #[cfg(any(target_os = "android", target_os = "linux"))]
144 pub fn preadv2
<Fd
: AsFd
>(
146 bufs
: &mut [IoSliceMut
<'_
>],
148 flags
: ReadWriteFlags
,
149 ) -> io
::Result
<usize> {
150 backend
::io
::syscalls
::preadv2(fd
.as_fd(), bufs
, offset
, flags
)
153 /// `pwritev2(fd, bufs, offset, flags)`—Writes data, with several options.
155 /// An `offset` of `u64::MAX` means to use and update the current file offset.
160 /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev2.2.html
161 #[cfg(any(target_os = "android", target_os = "linux"))]
163 pub fn pwritev2
<Fd
: AsFd
>(
165 bufs
: &[IoSlice
<'_
>],
167 flags
: ReadWriteFlags
,
168 ) -> io
::Result
<usize> {
169 backend
::io
::syscalls
::pwritev2(fd
.as_fd(), bufs
, offset
, flags
)