|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 | // |
6 | | -// spell-checker:ignore wincode serde utmp runlevel testusr testx boottime |
| 6 | +// spell-checker:ignore utmp runlevel testusr testx boottime |
7 | 7 | #![allow(clippy::cast_possible_wrap, clippy::unreadable_literal)] |
8 | 8 |
|
9 | 9 | use uutests::{at_and_ucmd, new_ucmd}; |
@@ -97,8 +97,6 @@ fn test_uptime_with_non_existent_file() { |
97 | 97 | fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { |
98 | 98 | use std::fs::File; |
99 | 99 | use std::{io::Write, path::PathBuf}; |
100 | | - use wincode::serialize; |
101 | | - use wincode_derive::SchemaWrite; |
102 | 100 |
|
103 | 101 | // This test will pass for freebsd but we currently don't support changing the utmpx file for |
104 | 102 | // freebsd. |
@@ -132,21 +130,18 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { |
132 | 130 | const RUN_LVL: i32 = 1; |
133 | 131 | const USER_PROCESS: i32 = 7; |
134 | 132 |
|
135 | | - #[derive(SchemaWrite)] |
136 | 133 | #[repr(C)] |
137 | 134 | pub struct TimeVal { |
138 | 135 | pub tv_sec: i32, |
139 | 136 | pub tv_usec: i32, |
140 | 137 | } |
141 | 138 |
|
142 | | - #[derive(SchemaWrite)] |
143 | 139 | #[repr(C)] |
144 | 140 | pub struct ExitStatus { |
145 | 141 | e_termination: i16, |
146 | 142 | e_exit: i16, |
147 | 143 | } |
148 | 144 |
|
149 | | - #[derive(SchemaWrite)] |
150 | 145 | #[repr(C, align(4))] |
151 | 146 | pub struct Utmp { |
152 | 147 | pub ut_type: i32, |
@@ -222,9 +217,35 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { |
222 | 217 | glibc_reserved: [0; 20], |
223 | 218 | }; |
224 | 219 |
|
225 | | - let mut buf = serialize(&utmp).unwrap(); |
226 | | - buf.append(&mut serialize(&utmp1).unwrap()); |
227 | | - buf.append(&mut serialize(&utmp2).unwrap()); |
| 220 | + fn serialize_i8_arr(buf: &mut Vec<u8>, arr: &[i8]) { |
| 221 | + for b in arr { |
| 222 | + buf.push(*b as u8); |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + fn serialize(utmp: &Utmp) -> Vec<u8> { |
| 227 | + let mut buf = Vec::new(); |
| 228 | + buf.extend_from_slice(&utmp.ut_type.to_ne_bytes()); |
| 229 | + buf.extend_from_slice(&utmp.ut_pid.to_ne_bytes()); |
| 230 | + serialize_i8_arr(&mut buf, &utmp.ut_line); |
| 231 | + serialize_i8_arr(&mut buf, &utmp.ut_id); |
| 232 | + serialize_i8_arr(&mut buf, &utmp.ut_user); |
| 233 | + serialize_i8_arr(&mut buf, &utmp.ut_host); |
| 234 | + buf.extend_from_slice(&utmp.ut_exit.e_termination.to_ne_bytes()); |
| 235 | + buf.extend_from_slice(&utmp.ut_exit.e_exit.to_ne_bytes()); |
| 236 | + buf.extend_from_slice(&utmp.ut_session.to_ne_bytes()); |
| 237 | + buf.extend_from_slice(&utmp.ut_tv.tv_sec.to_ne_bytes()); |
| 238 | + buf.extend_from_slice(&utmp.ut_tv.tv_usec.to_ne_bytes()); |
| 239 | + for v in &utmp.ut_addr_v6 { |
| 240 | + buf.extend_from_slice(&v.to_ne_bytes()); |
| 241 | + } |
| 242 | + serialize_i8_arr(&mut buf, &utmp.glibc_reserved); |
| 243 | + buf |
| 244 | + } |
| 245 | + |
| 246 | + let mut buf = serialize(&utmp); |
| 247 | + buf.append(&mut serialize(&utmp1)); |
| 248 | + buf.append(&mut serialize(&utmp2)); |
228 | 249 | let mut f = File::create(path).unwrap(); |
229 | 250 | f.write_all(&buf).unwrap(); |
230 | 251 | } |
|
0 commit comments