Skip to content

Commit 1ef4fc4

Browse files
committed
uucore: support cygwin
requires [libc patch](rust-lang/libc@a3bb40e), mio v1.1.0 and [nix patch](nix-rust/nix#\2708). behavior is mostly matched with Linux
1 parent ee39b35 commit 1ef4fc4

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

src/uucore/src/lib/features/fs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl FileInformation {
123123
not(target_os = "openbsd"),
124124
not(target_os = "illumos"),
125125
not(target_os = "solaris"),
126+
not(target_os = "cygwin"),
126127
not(target_arch = "aarch64"),
127128
not(target_arch = "riscv64"),
128129
not(target_arch = "loongarch64"),
@@ -140,6 +141,7 @@ impl FileInformation {
140141
target_os = "openbsd",
141142
target_os = "illumos",
142143
target_os = "solaris",
144+
target_os = "cygwin",
143145
target_arch = "aarch64",
144146
target_arch = "riscv64",
145147
target_arch = "loongarch64",

src/uucore/src/lib/features/fsext.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
88
// spell-checker:ignore DATETIME getmntinfo subsecond (fs) cifs smbfs
99

10-
#[cfg(any(target_os = "linux", target_os = "android"))]
10+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
1111
const LINUX_MTAB: &str = "/etc/mtab";
12-
#[cfg(any(target_os = "linux", target_os = "android"))]
12+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
1313
const LINUX_MOUNTINFO: &str = "/proc/self/mountinfo";
1414
#[cfg(all(unix, not(any(target_os = "aix", target_os = "redox"))))]
1515
static MOUNT_OPT_BIND: &str = "bind";
@@ -94,7 +94,8 @@ pub use libc::statfs as StatFs;
9494
target_os = "dragonfly",
9595
target_os = "illumos",
9696
target_os = "solaris",
97-
target_os = "redox"
97+
target_os = "redox",
98+
target_os = "cygwin",
9899
))]
99100
pub use libc::statvfs as StatFs;
100101

@@ -112,7 +113,8 @@ pub use libc::statfs as statfs_fn;
112113
target_os = "illumos",
113114
target_os = "solaris",
114115
target_os = "dragonfly",
115-
target_os = "redox"
116+
target_os = "redox",
117+
target_os = "cygwin",
116118
))]
117119
pub use libc::statvfs as statfs_fn;
118120

@@ -189,7 +191,7 @@ pub struct MountInfo {
189191
pub dummy: bool,
190192
}
191193

192-
#[cfg(any(target_os = "linux", target_os = "android"))]
194+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
193195
fn replace_special_chars(s: &[u8]) -> Vec<u8> {
194196
use bstr::ByteSlice;
195197

@@ -205,7 +207,7 @@ fn replace_special_chars(s: &[u8]) -> Vec<u8> {
205207
}
206208

207209
impl MountInfo {
208-
#[cfg(any(target_os = "linux", target_os = "android"))]
210+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
209211
fn new(file_name: &str, raw: &[&[u8]]) -> Option<Self> {
210212
use std::ffi::OsStr;
211213
use std::os::unix::ffi::OsStrExt;
@@ -459,9 +461,9 @@ use crate::error::UResult;
459461
target_os = "windows"
460462
))]
461463
use crate::error::USimpleError;
462-
#[cfg(any(target_os = "linux", target_os = "android"))]
464+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
463465
use std::fs::File;
464-
#[cfg(any(target_os = "linux", target_os = "android"))]
466+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
465467
use std::io::{BufRead, BufReader};
466468
#[cfg(any(
467469
target_vendor = "apple",
@@ -481,7 +483,7 @@ use std::slice;
481483

482484
/// Read file system list.
483485
pub fn read_fs_list() -> UResult<Vec<MountInfo>> {
484-
#[cfg(any(target_os = "linux", target_os = "android"))]
486+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))]
485487
{
486488
let (file_name, f) = File::open(LINUX_MOUNTINFO)
487489
.map(|f| (LINUX_MOUNTINFO, f))
@@ -722,6 +724,7 @@ impl FsMeta for StatFs {
722724
not(target_os = "solaris"),
723725
not(target_os = "redox"),
724726
not(target_arch = "s390x"),
727+
not(target_os = "cygwin"),
725728
target_pointer_width = "64"
726729
))]
727730
return self.f_bsize;
@@ -730,6 +733,7 @@ impl FsMeta for StatFs {
730733
not(target_os = "freebsd"),
731734
not(target_os = "netbsd"),
732735
not(target_os = "redox"),
736+
not(target_os = "cygwin"),
733737
any(
734738
target_arch = "s390x",
735739
target_vendor = "apple",
@@ -747,6 +751,7 @@ impl FsMeta for StatFs {
747751
target_os = "illumos",
748752
target_os = "solaris",
749753
target_os = "redox",
754+
target_os = "cygwin",
750755
all(target_os = "android", target_pointer_width = "64"),
751756
))]
752757
return self.f_bsize.try_into().unwrap();

src/uucore/src/lib/features/signals.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,48 @@ pub static ALL_SIGNALS: [&str; 37] = [
346346
"VIRT", "TALRM",
347347
];
348348

349+
/*
350+
The following signals are defined in Cygwin
351+
352+
SIGHUP: 1
353+
SIGINT: 2
354+
SIGQUIT: 3
355+
SIGILL: 4
356+
SIGTRAP: 5
357+
SIGABRT: 6
358+
SIGEMT: 7
359+
SIGFPE: 8
360+
SIGKILL: 9
361+
SIGBUS: 10
362+
SIGSEGV: 11
363+
SIGSYS: 12
364+
SIGPIPE: 13
365+
SIGALRM: 14
366+
SIGTERM: 15
367+
SIGURG: 16
368+
SIGSTOP: 17
369+
SIGTSTP: 18
370+
SIGCONT: 19
371+
SIGCHLD: 20
372+
SIGTTIN: 21
373+
SIGTTOU: 22
374+
SIGIO: 23
375+
SIGXCPU: 24
376+
SIGXFSZ: 25
377+
SIGVTALRM: 26
378+
SIGPROF: 27
379+
SIGWINCH: 28
380+
SIGPWR: 29
381+
SIGUSR1: 30
382+
SIGUSR2: 31
383+
*/
384+
#[cfg(target_os = "cygwin")]
385+
pub static ALL_SIGNALS: [&str; 32] = [
386+
"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "EMT", "FPE", "KILL", "BUS", "SEGV",
387+
"SYS", "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", "CONT", "CHLD", "TTIN", "TTOU", "IO",
388+
"XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "PWR", "USR1", "USR2",
389+
];
390+
349391
/// Returns the signal number for a given signal name or value.
350392
pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<usize> {
351393
let signal_name_upcase = signal_name_or_value.to_uppercase();

0 commit comments

Comments
 (0)