Skip to content

Commit fa71913

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 fa71913

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
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: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
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 (vars/api) fcntl setrlimit setitimer rubout pollable sysconf
7-
// spell-checker:ignore (vars/signals) ABRT ALRM CHLD SEGV SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGDANGER SIGEMT SIGFPE SIGHUP SIGILL SIGINFO SIGINT SIGIO SIGIOT SIGKILL SIGMIGRATE SIGMSG SIGPIPE SIGPRE SIGPROF SIGPWR SIGQUIT SIGSEGV SIGSTOP SIGSYS SIGTALRM SIGTERM SIGTRAP SIGTSTP SIGTHR SIGTTIN SIGTTOU SIGURG SIGUSR SIGVIRT SIGVTALRM SIGWINCH SIGXCPU SIGXFSZ STKFLT PWR THR TSTP TTIN TTOU VIRT VTALRM XCPU XFSZ SIGCLD SIGPOLL SIGWAITING SIGAIOCANCEL SIGLWP SIGFREEZE SIGTHAW SIGCANCEL SIGLOST SIGXRES SIGJVM SIGRTMIN SIGRT SIGRTMAX TALRM AIOCANCEL XRES RTMIN RTMAX
6+
// spell-checker:ignore (vars/api) fcntl setrlimit setitimer rubout pollable sysconf pgrp
7+
// spell-checker:ignore (vars/signals) ABRT ALRM CHLD SEGV SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGDANGER SIGEMT SIGFPE SIGHUP SIGILL SIGINFO SIGINT SIGIO SIGIOT SIGKILL SIGMIGRATE SIGMSG SIGPIPE SIGPRE SIGPROF SIGPWR SIGQUIT SIGSEGV SIGSTOP SIGSYS SIGTALRM SIGTERM SIGTRAP SIGTSTP SIGTHR SIGTTIN SIGTTOU SIGURG SIGUSR SIGVIRT SIGVTALRM SIGWINCH SIGXCPU SIGXFSZ STKFLT PWR THR TSTP TTIN TTOU VIRT VTALRM XCPU XFSZ SIGCLD SIGPOLL SIGWAITING SIGAIOCANCEL SIGLWP SIGFREEZE SIGTHAW SIGCANCEL SIGLOST SIGXRES SIGJVM SIGRTMIN SIGRT SIGRTMAX TALRM AIOCANCEL XRES RTMIN RTMAX LTOSTOP
88

99
//! This module provides a way to handle signals in a platform-independent way.
1010
//! It provides a way to convert signal names to their corresponding values and vice versa.
@@ -346,6 +346,49 @@ pub static ALL_SIGNALS: [&str; 37] = [
346346
"VIRT", "TALRM",
347347
];
348348

349+
/*
350+
The following signals are defined in Cygwin
351+
https://cygwin.com/cgit/newlib-cygwin/tree/winsup/cygwin/include/cygwin/signal.h
352+
353+
SIGHUP 1 hangup
354+
SIGINT 2 interrupt
355+
SIGQUIT 3 quit
356+
SIGILL 4 illegal instruction (not reset when caught)
357+
SIGTRAP 5 trace trap (not reset when caught)
358+
SIGABRT 6 used by abort
359+
SIGEMT 7 EMT instruction
360+
SIGFPE 8 floating point exception
361+
SIGKILL 9 kill (cannot be caught or ignored)
362+
SIGBUS 10 bus error
363+
SIGSEGV 11 segmentation violation
364+
SIGSYS 12 bad argument to system call
365+
SIGPIPE 13 write on a pipe with no one to read it
366+
SIGALRM 14 alarm clock
367+
SIGTERM 15 software termination signal from kill
368+
SIGURG 16 urgent condition on IO channel
369+
SIGSTOP 17 sendable stop signal not from tty
370+
SIGTSTP 18 stop signal from tty
371+
SIGCONT 19 continue a stopped process
372+
SIGCHLD 20 to parent on child stop or exit
373+
SIGTTIN 21 to readers pgrp upon background tty read
374+
SIGTTOU 22 like TTIN for output if (tp->t_local&LTOSTOP)
375+
SIGIO 23 input/output possible signal
376+
SIGXCPU 24 exceeded CPU time limit
377+
SIGXFSZ 25 exceeded file size limit
378+
SIGVTALRM 26 virtual time alarm
379+
SIGPROF 27 profiling time alarm
380+
SIGWINCH 28 window changed
381+
SIGLOST 29 resource lost (eg, record-lock lost)
382+
SIGUSR1 30 user defined signal 1
383+
SIGUSR2 31 user defined signal 2
384+
*/
385+
#[cfg(target_os = "cygwin")]
386+
pub static ALL_SIGNALS: [&str; 32] = [
387+
"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "EMT", "FPE", "KILL", "BUS", "SEGV",
388+
"SYS", "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", "CONT", "CHLD", "TTIN", "TTOU", "IO",
389+
"XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "PWR", "USR1", "USR2",
390+
];
391+
349392
/// Returns the signal number for a given signal name or value.
350393
pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<usize> {
351394
let signal_name_upcase = signal_name_or_value.to_uppercase();

0 commit comments

Comments
 (0)