Skip to content

Commit 2a45733

Browse files
authored
Remove wincode and wincode-derive dependencies (uutils#10802)
1 parent 52a5b48 commit 2a45733

File tree

3 files changed

+31
-88
lines changed

3 files changed

+31
-88
lines changed

Cargo.lock

Lines changed: 0 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coreutils (uutils)
22
# * see the repository LICENSE, README, and CONTRIBUTING files for more information
33

4-
# spell-checker:ignore (libs) bigdecimal datetime serde wincode gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind cfgs interner
4+
# spell-checker:ignore (libs) bigdecimal datetime serde gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind cfgs interner
55

66
[package]
77
name = "coreutils"
@@ -587,11 +587,6 @@ nix = { workspace = true, features = [
587587
] }
588588
rlimit = { workspace = true }
589589

590-
# Used in test_uptime::test_uptime_with_file_containing_valid_boot_time_utmpx_record
591-
# to deserialize an utmpx struct into a binary file
592-
[target.'cfg(all(target_family= "unix",not(target_os = "macos")))'.dev-dependencies]
593-
wincode = "0.3.1"
594-
wincode-derive = "0.3.1"
595590

596591
[build-dependencies]
597592
phf_codegen.workspace = true

tests/by-util/test_uptime.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55
//
6-
// spell-checker:ignore wincode serde utmp runlevel testusr testx boottime
6+
// spell-checker:ignore utmp runlevel testusr testx boottime
77
#![allow(clippy::cast_possible_wrap, clippy::unreadable_literal)]
88

99
use uutests::{at_and_ucmd, new_ucmd};
@@ -97,8 +97,6 @@ fn test_uptime_with_non_existent_file() {
9797
fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
9898
use std::fs::File;
9999
use std::{io::Write, path::PathBuf};
100-
use wincode::serialize;
101-
use wincode_derive::SchemaWrite;
102100

103101
// This test will pass for freebsd but we currently don't support changing the utmpx file for
104102
// freebsd.
@@ -132,21 +130,18 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
132130
const RUN_LVL: i32 = 1;
133131
const USER_PROCESS: i32 = 7;
134132

135-
#[derive(SchemaWrite)]
136133
#[repr(C)]
137134
pub struct TimeVal {
138135
pub tv_sec: i32,
139136
pub tv_usec: i32,
140137
}
141138

142-
#[derive(SchemaWrite)]
143139
#[repr(C)]
144140
pub struct ExitStatus {
145141
e_termination: i16,
146142
e_exit: i16,
147143
}
148144

149-
#[derive(SchemaWrite)]
150145
#[repr(C, align(4))]
151146
pub struct Utmp {
152147
pub ut_type: i32,
@@ -222,9 +217,35 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
222217
glibc_reserved: [0; 20],
223218
};
224219

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));
228249
let mut f = File::create(path).unwrap();
229250
f.write_all(&buf).unwrap();
230251
}

0 commit comments

Comments
 (0)