]> git.proxmox.com Git - rustc.git/blob - vendor/rustix-0.36.5/src/backend/linux_raw/io/types.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / vendor / rustix-0.36.5 / src / backend / linux_raw / io / types.rs
1 use super::super::c;
2 use bitflags::bitflags;
3 use core::marker::PhantomData;
4
5 bitflags! {
6 /// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`].
7 ///
8 /// [`fcntl_getfd`]: crate::io::fcntl_getfd
9 /// [`fcntl_setfd`]: crate::io::fcntl_setfd
10 pub struct FdFlags: c::c_uint {
11 /// `FD_CLOEXEC`
12 const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC;
13 }
14 }
15
16 bitflags! {
17 /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].
18 ///
19 /// [`preadv2`]: crate::io::preadv2
20 /// [`pwritev2`]: crate::io::pwritev
21 pub struct ReadWriteFlags: c::c_uint {
22 /// `RWF_DSYNC` (since Linux 4.7)
23 const DSYNC = linux_raw_sys::general::RWF_DSYNC;
24 /// `RWF_HIPRI` (since Linux 4.6)
25 const HIPRI = linux_raw_sys::general::RWF_HIPRI;
26 /// `RWF_SYNC` (since Linux 4.7)
27 const SYNC = linux_raw_sys::general::RWF_SYNC;
28 /// `RWF_NOWAIT` (since Linux 4.14)
29 const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
30 /// `RWF_APPEND` (since Linux 4.16)
31 const APPEND = linux_raw_sys::general::RWF_APPEND;
32 }
33 }
34
35 #[cfg(any(target_os = "android", target_os = "linux"))]
36 bitflags! {
37 /// `SPLICE_F_*` constants for use with [`splice`] and [`vmsplice`].
38 pub struct SpliceFlags: c::c_uint {
39 /// `SPLICE_F_MOVE`
40 const MOVE = linux_raw_sys::general::SPLICE_F_MOVE;
41 /// `SPLICE_F_NONBLOCK`
42 const NONBLOCK = linux_raw_sys::general::SPLICE_F_NONBLOCK;
43 /// `SPLICE_F_MORE`
44 const MORE = linux_raw_sys::general::SPLICE_F_MORE;
45 /// `SPLICE_F_GIFT`
46 const GIFT = linux_raw_sys::general::SPLICE_F_GIFT;
47 }
48 }
49
50 bitflags! {
51 /// `O_*` constants for use with [`dup2`].
52 ///
53 /// [`dup2`]: crate::io::dup2
54 pub struct DupFlags: c::c_uint {
55 /// `O_CLOEXEC`
56 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
57 }
58 }
59
60 bitflags! {
61 /// `O_*` constants for use with [`pipe_with`].
62 ///
63 /// [`pipe_with`]: crate::io::pipe_with
64 pub struct PipeFlags: c::c_uint {
65 /// `O_CLOEXEC`
66 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
67 /// `O_DIRECT`
68 const DIRECT = linux_raw_sys::general::O_DIRECT;
69 /// `O_NONBLOCK`
70 const NONBLOCK = linux_raw_sys::general::O_NONBLOCK;
71 }
72 }
73
74 bitflags! {
75 /// `EFD_*` flags for use with [`eventfd`].
76 ///
77 /// [`eventfd`]: crate::io::eventfd
78 pub struct EventfdFlags: c::c_uint {
79 /// `EFD_CLOEXEC`
80 const CLOEXEC = linux_raw_sys::general::EFD_CLOEXEC;
81 /// `EFD_NONBLOCK`
82 const NONBLOCK = linux_raw_sys::general::EFD_NONBLOCK;
83 /// `EFD_SEMAPHORE`
84 const SEMAPHORE = linux_raw_sys::general::EFD_SEMAPHORE;
85 }
86 }
87
88 /// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic.
89 pub const PIPE_BUF: usize = linux_raw_sys::general::PIPE_BUF as usize;
90
91 pub(crate) const AT_FDCWD: c::c_int = linux_raw_sys::general::AT_FDCWD;
92 pub(crate) const STDIN_FILENO: c::c_uint = linux_raw_sys::general::STDIN_FILENO;
93 pub(crate) const STDOUT_FILENO: c::c_uint = linux_raw_sys::general::STDOUT_FILENO;
94 pub(crate) const STDERR_FILENO: c::c_uint = linux_raw_sys::general::STDERR_FILENO;
95
96 /// A buffer type used with `vmsplice`.
97 /// It is guaranteed to be ABI compatible with the iovec type on Unix platforms and WSABUF on Windows.
98 /// Unlike `IoSlice` and `IoSliceMut` it is semantically like a raw pointer,
99 /// and therefore can be shared or mutated as needed.
100 #[repr(transparent)]
101 pub struct IoSliceRaw<'a> {
102 _buf: c::iovec,
103 _lifetime: PhantomData<&'a ()>,
104 }
105
106 impl<'a> IoSliceRaw<'a> {
107 /// Creates a new IoSlice wrapping a byte slice.
108 pub fn from_slice(buf: &'a [u8]) -> Self {
109 IoSliceRaw {
110 _buf: c::iovec {
111 iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void,
112 iov_len: buf.len() as _,
113 },
114 _lifetime: PhantomData,
115 }
116 }
117
118 /// Creates a new IoSlice wrapping a mutable byte slice.
119 pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
120 IoSliceRaw {
121 _buf: c::iovec {
122 iov_base: buf.as_mut_ptr() as *mut c::c_void,
123 iov_len: buf.len() as _,
124 },
125 _lifetime: PhantomData,
126 }
127 }
128 }