Skip to content

Commit 0922fd9

Browse files
bors[bot]rtzoeller
andauthored
Merge #1693
1693: Document aliases for functions like getuid() r=asomers a=rtzoeller Add the autocfg crate as a build dependency, and introduce `has_doc_alias` as a conditional compilation symbol. Closes #1673. Co-authored-by: Ryan Zoeller <[email protected]>
2 parents 84b02b9 + 1fa1bb1 commit 0922fd9

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pin-utils = { version = "0.1.0", optional = true }
3535
[target.'cfg(not(target_os = "redox"))'.dependencies]
3636
memoffset = { version = "0.6.3", optional = true }
3737

38+
[build-dependencies]
39+
autocfg = "1.1.0"
40+
3841
[features]
3942
default = [
4043
"acct", "aio", "dir", "env", "event", "feature", "fs",

build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let cfg = autocfg::new();
3+
4+
if cfg.probe_rustc_version(1, 52) {
5+
autocfg::emit("has_doc_alias");
6+
}
7+
}

src/dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl Dir {
5353
}
5454

5555
/// Converts from a file descriptor, closing it on success or failure.
56+
#[cfg_attr(has_doc_alias, doc(alias("fdopendir")))]
5657
pub fn from_fd(fd: RawFd) -> Result<Self> {
5758
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
5859
let e = Error::last();

src/sys/signal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ pub struct SigSet {
472472

473473
impl SigSet {
474474
/// Initialize to include all signals.
475+
#[cfg_attr(has_doc_alias, doc(alias("sigfillset")))]
475476
pub fn all() -> SigSet {
476477
let mut sigset = mem::MaybeUninit::uninit();
477478
let _ = unsafe { libc::sigfillset(sigset.as_mut_ptr()) };
@@ -480,6 +481,7 @@ impl SigSet {
480481
}
481482

482483
/// Initialize to include nothing.
484+
#[cfg_attr(has_doc_alias, doc(alias("sigemptyset")))]
483485
pub fn empty() -> SigSet {
484486
let mut sigset = mem::MaybeUninit::uninit();
485487
let _ = unsafe { libc::sigemptyset(sigset.as_mut_ptr()) };
@@ -488,21 +490,25 @@ impl SigSet {
488490
}
489491

490492
/// Add the specified signal to the set.
493+
#[cfg_attr(has_doc_alias, doc(alias("sigaddset")))]
491494
pub fn add(&mut self, signal: Signal) {
492495
unsafe { libc::sigaddset(&mut self.sigset as *mut libc::sigset_t, signal as libc::c_int) };
493496
}
494497

495498
/// Remove all signals from this set.
499+
#[cfg_attr(has_doc_alias, doc(alias("sigemptyset")))]
496500
pub fn clear(&mut self) {
497501
unsafe { libc::sigemptyset(&mut self.sigset as *mut libc::sigset_t) };
498502
}
499503

500504
/// Remove the specified signal from this set.
505+
#[cfg_attr(has_doc_alias, doc(alias("sigdelset")))]
501506
pub fn remove(&mut self, signal: Signal) {
502507
unsafe { libc::sigdelset(&mut self.sigset as *mut libc::sigset_t, signal as libc::c_int) };
503508
}
504509

505510
/// Return whether this set includes the specified signal.
511+
#[cfg_attr(has_doc_alias, doc(alias("sigismember")))]
506512
pub fn contains(&self, signal: Signal) -> bool {
507513
let res = unsafe { libc::sigismember(&self.sigset as *const libc::sigset_t, signal as libc::c_int) };
508514

src/sys/timer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub struct Timer(libc::timer_t);
7070
impl Timer {
7171
/// Creates a new timer based on the clock defined by `clockid`. The details
7272
/// of the signal and its handler are defined by the passed `sigevent`.
73+
#[cfg_attr(has_doc_alias, doc(alias("timer_create")))]
7374
pub fn new(clockid: ClockId, mut sigevent: SigEvent) -> Result<Self> {
7475
let mut timer_id: mem::MaybeUninit<libc::timer_t> = mem::MaybeUninit::uninit();
7576
Errno::result(unsafe {
@@ -122,6 +123,7 @@ impl Timer {
122123
///
123124
/// Note: Setting a one shot alarm with a 0s TimeSpec disable the alarm
124125
/// altogether.
126+
#[cfg_attr(has_doc_alias, doc(alias("timer_settime")))]
125127
pub fn set(&mut self, expiration: Expiration, flags: TimerSetTimeFlags) -> Result<()> {
126128
let timerspec: TimerSpec = expiration.into();
127129
Errno::result(unsafe {
@@ -136,6 +138,7 @@ impl Timer {
136138
}
137139

138140
/// Get the parameters for the alarm currently set, if any.
141+
#[cfg_attr(has_doc_alias, doc(alias("timer_gettime")))]
139142
pub fn get(&self) -> Result<Option<Expiration>> {
140143
let mut timerspec = TimerSpec::none();
141144
Errno::result(unsafe { libc::timer_gettime(self.0, timerspec.as_mut()) }).map(|_| {
@@ -158,6 +161,7 @@ impl Timer {
158161
/// 'overrun'. This function returns how many times that has happened to
159162
/// this timer, up to `libc::DELAYTIMER_MAX`. If more than the maximum
160163
/// number of overruns have happened the return is capped to the maximum.
164+
#[cfg_attr(has_doc_alias, doc(alias("timer_getoverrun")))]
161165
pub fn overruns(&self) -> i32 {
162166
unsafe { libc::timer_getoverrun(self.0) }
163167
}

src/sys/timerfd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl TimerFd {
9292
/// Creates a new timer based on the clock defined by `clockid`. The
9393
/// underlying fd can be assigned specific flags with `flags` (CLOEXEC,
9494
/// NONBLOCK). The underlying fd will be closed on drop.
95+
#[cfg_attr(has_doc_alias, doc(alias("timerfd_create")))]
9596
pub fn new(clockid: ClockId, flags: TimerFlags) -> Result<Self> {
9697
Errno::result(unsafe { libc::timerfd_create(clockid as i32, flags.bits()) })
9798
.map(|fd| Self { fd })
@@ -133,6 +134,7 @@ impl TimerFd {
133134
///
134135
/// Note: Setting a one shot alarm with a 0s TimeSpec disables the alarm
135136
/// altogether.
137+
#[cfg_attr(has_doc_alias, doc(alias("timerfd_settime")))]
136138
pub fn set(&self, expiration: Expiration, flags: TimerSetTimeFlags) -> Result<()> {
137139
let timerspec: TimerSpec = expiration.into();
138140
Errno::result(unsafe {
@@ -147,6 +149,7 @@ impl TimerFd {
147149
}
148150

149151
/// Get the parameters for the alarm currently set, if any.
152+
#[cfg_attr(has_doc_alias, doc(alias("timerfd_gettime")))]
150153
pub fn get(&self) -> Result<Option<Expiration>> {
151154
let mut timerspec = TimerSpec::none();
152155
Errno::result(unsafe { libc::timerfd_gettime(self.fd, timerspec.as_mut()) }).map(|_| {
@@ -163,6 +166,7 @@ impl TimerFd {
163166
}
164167

165168
/// Remove the alarm if any is set.
169+
#[cfg_attr(has_doc_alias, doc(alias("timerfd_settime")))]
166170
pub fn unset(&self) -> Result<()> {
167171
Errno::result(unsafe {
168172
libc::timerfd_settime(

src/unistd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ impl Uid {
6767
}
6868

6969
/// Returns Uid of calling process. This is practically a more Rusty alias for `getuid`.
70+
#[cfg_attr(has_doc_alias, doc(alias("getuid")))]
7071
pub fn current() -> Self {
7172
getuid()
7273
}
7374

7475
/// Returns effective Uid of calling process. This is practically a more Rusty alias for `geteuid`.
76+
#[cfg_attr(has_doc_alias, doc(alias("geteuid")))]
7577
pub fn effective() -> Self {
7678
geteuid()
7779
}
@@ -122,11 +124,13 @@ impl Gid {
122124
}
123125

124126
/// Returns Gid of calling process. This is practically a more Rusty alias for `getgid`.
127+
#[cfg_attr(has_doc_alias, doc(alias("getgid")))]
125128
pub fn current() -> Self {
126129
getgid()
127130
}
128131

129132
/// Returns effective Gid of calling process. This is practically a more Rusty alias for `getegid`.
133+
#[cfg_attr(has_doc_alias, doc(alias("getegid")))]
130134
pub fn effective() -> Self {
131135
getegid()
132136
}
@@ -172,11 +176,13 @@ impl Pid {
172176
}
173177

174178
/// Returns PID of calling process
179+
#[cfg_attr(has_doc_alias, doc(alias("getpid")))]
175180
pub fn this() -> Self {
176181
getpid()
177182
}
178183

179184
/// Returns PID of parent of calling process
185+
#[cfg_attr(has_doc_alias, doc(alias("getppid")))]
180186
pub fn parent() -> Self {
181187
getppid()
182188
}

0 commit comments

Comments
 (0)