Debian Codegraph @

src/cutils/mod.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
2 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, c_longrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_long#},
3 osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::{
4 fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#},
5 unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/prelude/::OsStrExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/OsStrExt#,
6 },
7 };
8
9 pub fn cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().<Int: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#<c_longrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_long#>>(res: Int) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Int> {
10 match res.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().() {
11 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(-1) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()),
12 _ => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res),
13 }
14 }
15
16 unsafe extern "C" {
17 #[cfg_attr(
18 any(target_os = "macos", target_os = "ios", target_os = "freebsd"),
19 link_name = "__error"
20 )]
21 #[cfg_attr(
22 any(target_os = "openbsd", target_os = "netbsd", target_os = "android"),
23 link_name = "__errno"
24 )]
25 #[cfg_attr(target_os = "linux", link_name = "__errno_location")]
26 safe fn errno_locationrust-analyzer cargo sudo-rs 0.2.14 errno_location().() -> *mut c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#;
27 }
28
29 pub fn set_errnorust-analyzer cargo sudo-rs 0.2.14 cutils/set_errno().(no: c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#) {
30 // SAFETY: errno_location is a thread-local pointer to an integer, so we are the only writers
31 unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().errno_locationrust-analyzer cargo sudo-rs 0.2.14 errno_location().() = no };
32 }
33
34 pub fn sysconfrust-analyzer cargo sudo-rs 0.2.14 cutils/sysconf().(name: c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<c_longrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_long#> {
35 set_errnorust-analyzer cargo sudo-rs 0.2.14 cutils/set_errno().(0);
36 // SAFETY: sysconf will always respond with 0 or -1 for every input
37 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::sysconfrust-analyzer cargo libc 0.2.186 sysconf().(name) }).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
38 }
39
40 /// Create a Rust string copy from a C string pointer
41 /// WARNING: This uses `to_string_lossy` so should not be used for data where
42 /// information loss is unacceptable (use `os_string_from_ptr` instead)
43 ///
44 /// # Safety
45 /// This function assumes that the pointer is either a null pointer or that
46 /// it points to a valid NUL-terminated C string.
47 pub unsafe fn string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/string_from_ptr().(ptr: *const c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
48 if ptr.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() {
49 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()
50 } else {
51 // SAFETY: the function contract says that CStr::from_ptr is safe
52 let cstr = unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(ptr) };
53 cstr.to_string_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CStr]to_string_lossy().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
54 }
55 }
56
57 /// Create an `OsString` copy from a C string pointer.
58 ///
59 /// # Safety
60 /// This function assumes that the pointer is either a null pointer or that
61 /// it points to a valid NUL-terminated C string.
62 pub unsafe fn os_string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/os_string_from_ptr().(ptr: *const c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#) -> OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString# {
63 if ptr.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() {
64 OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]new().()
65 } else {
66 // SAFETY: the function contract says that CStr::from_ptr is safe
67 let cstr = unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(ptr) };
68 OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::from_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]from_bytes().(cstr.to_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_bytes().()).to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr][ToOwned]to_owned().()
69 }
70 }
71
72 fn fstat_mode_anyrust-analyzer cargo sudo-rs 0.2.14 cutils/fstat_mode_any().<const MASK: libcrust-analyzer cargo libc 0.2.186 crate/::mode_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/mode_t#>(fildes: &BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#) -> bool {
73 const {
74 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(MASK &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). libcrust-analyzer cargo libc 0.2.186 crate/::S_IFMTrust-analyzer cargo libc 0.2.186 unix/linux_like/S_IFMT. == MASK);
75 }
76
77 // The Rust standard library doesn't have FileTypeExt on Std{in,out,err}, so we
78 // can't just use FileTypeExt::is_char_device and have to resort to libc::fstat.
79 let mut maybe_stat = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<libcrust-analyzer cargo libc 0.2.186 crate/::statrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/stat#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
80
81 // SAFETY: we are passing fstat a pointer to valid memory
82 if unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::fstatrust-analyzer cargo libc 0.2.186 fstat().(fildes.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), maybe_stat.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 {
83 // SAFETY: if `fstat` returned 0, maybe_stat will be initialized
84 let mode = unsafe { maybe_stat.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().() }.st_moderust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/stat#st_mode.;
85
86 // To complicate matters further, the S_ISCHR macro isn't in libc as well.
87 (mode rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().MASK) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0
88 } else {
89 false
90 }
91 }
92
93 /// Rust's standard library IsTerminal just directly calls isatty, which
94 /// we don't want since this performs IOCTL calls on them and file descriptors are under
95 /// the control of the user; so this checks if they are a character device first.
96 pub fn safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(fildes: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#) -> bool {
97 let is_char_device = fstat_mode_anyrust-analyzer cargo sudo-rs 0.2.14 cutils/fstat_mode_any().::<{ libcrust-analyzer cargo libc 0.2.186 crate/::S_IFCHRrust-analyzer cargo libc 0.2.186 unix/linux_like/S_IFCHR. }>(&fildes);
98
99 if is_char_device {
100 // SAFETY: isatty will return 0 or 1
101 unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::isattyrust-analyzer cargo libc 0.2.186 isatty().(fildes.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 }
102 } else {
103 false
104 }
105 }
106
107 /// Check whether the file descriptor is a pipe or socket
108 pub fn is_fifo_or_sockrust-analyzer cargo sudo-rs 0.2.14 cutils/is_fifo_or_sock().(fildes: BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#) -> bool {
109 fstat_mode_anyrust-analyzer cargo sudo-rs 0.2.14 cutils/fstat_mode_any().::<{ libcrust-analyzer cargo libc 0.2.186 crate/::S_IFIFOrust-analyzer cargo libc 0.2.186 unix/linux_like/S_IFIFO. | libcrust-analyzer cargo libc 0.2.186 crate/::S_IFSOCKrust-analyzer cargo libc 0.2.186 unix/linux_like/S_IFSOCK. }>(&fildes)
110 }
111
112 /// Dynamically obtain the correct buffer size (within bounds)
113 pub fn dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill().<T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#, E>(
114 range: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>,
115 mut fill: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut [T]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, E>,
116 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>>, E> {
117 let mut buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(); range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.];
118 loop {
119 match fill(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
120 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(len) => {
121 buffer.resize_withrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize_with().(len, || {
122 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("closure returned a buffer size that was larger than the input, this should not happen")
123 });
124
125 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(buffer));
126 }
127
128 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
129 if buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. {
130 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
131 } else {
132 buffer.resize_withrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize_with().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2, range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.), T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().)
133 }
134 }
135 }
136 }
137 }
138
139 #[allow(clippy::undocumented_unsafe_blocks)]
140 #[cfg(test)]
141 mod testrust-analyzer cargo sudo-rs 0.2.14 cutils/test/ {
142
143 use superrust-analyzer cargo sudo-rs 0.2.14 cutils/::{dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill()., os_string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/os_string_from_ptr()., string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/string_from_ptr().};
144
145 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
146 fn miri_test_str_to_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/test/miri_test_str_to_ptr().() {
147 let strp = |ptr| unsafe { string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/string_from_ptr().(ptr) };
148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().()), "");
149 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(c"".as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), "");
150 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(c"hello".as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), "hello");
151 }
152
153 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
154 fn miri_test_os_str_to_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/test/miri_test_os_str_to_ptr().() {
155 let strp = |ptr| unsafe { os_string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/os_string_from_ptr().(ptr) };
156 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().()), "");
157 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(c"".as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), "");
158 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strp(c"hello".as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()), "hello");
159 }
160
161 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
162 fn test_ttyrust-analyzer cargo sudo-rs 0.2.14 cutils/test/test_tty().() {
163 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::termrust-analyzer cargo sudo-rs 0.2.14 system/term/::Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#;
164 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#;
165 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#, BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#};
166 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().superrust-analyzer cargo sudo-rs 0.2.14 cutils/::safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().("/bin/sh").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()));
167 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().superrust-analyzer cargo sudo-rs 0.2.14 cutils/::safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(unsafe {
168 BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#::borrow_rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`]borrow_raw().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().837492)
169 }));
170 let pty = Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#::openrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty]open().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
171 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(superrust-analyzer cargo sudo-rs 0.2.14 cutils/::safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(pty.leaderrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#leader..as_fdrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader][AsFd]as_fd().()));
172 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(superrust-analyzer cargo sudo-rs 0.2.14 cutils/::safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(pty.followerrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#follower..as_fdrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyFollower][AsFd]as_fd().()));
173 }
174
175 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
176 fn test_dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/test/test_dynamic_fill().() {
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
178 dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill().(1..50, |buf: &mut [u8]| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>({
179 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). 50);
180 (buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 23).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(23)
181 }))
182 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
183 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
184 .lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
185 23
186 );
187
188 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
189 dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill().(1..50, |buf: &mut [u8]| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>({
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() <= 50);
191 (buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 50).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(23)
192 }))
193 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
194 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
195 .lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
196 23
197 );
198
199 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
200 dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill().(1..50, |buf: &mut [u8]| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>({
201 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() <= 50);
202 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
203 }))
204 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
205 .is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
206 );
207
208 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
209 dynamic_fillrust-analyzer cargo sudo-rs 0.2.14 cutils/dynamic_fill().(1..50, |buf: &mut [u8]| {
210 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() == 1);
211 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(())
212 })
213 .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()
214 );
215 }
216 }