Skip to content

Commit 5fde28e

Browse files
authored
docs: update docs of xxat() fns (#2444)
1 parent d60f710 commit 5fde28e

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

src/fcntl.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use crate::{sys::stat::Mode, NixPath, Result};
4141
#[cfg(feature = "fs")]
4242
pub use self::posix_fadvise::{posix_fadvise, PosixFadviseAdvice};
4343

44-
/// A file descriptor referring to the working directory of the current process.
44+
/// A file descriptor referring to the working directory of the current process
45+
/// **that should be ONLY passed to the `dirfd` argument of those `xxat()` functions**.
4546
///
4647
/// # Examples
4748
///
@@ -262,7 +263,7 @@ pub fn open<P: ?Sized + NixPath>(
262263
///
263264
/// The `openat` function is equivalent to the [`open`] function except in the case where the path
264265
/// specifies a relative path. In that case, the file to be opened is determined relative to the
265-
/// directory associated with the file descriptor `fd`.
266+
/// directory associated with the file descriptor `dirfd`.
266267
///
267268
/// # See Also
268269
/// [`openat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html)
@@ -324,9 +325,11 @@ cfg_if::cfg_if! {
324325
}
325326
}
326327

327-
/// Specifies how [openat2] should open a pathname.
328+
/// Specifies how [`openat2()`] should open a pathname.
328329
///
329-
/// See <https://man7.org/linux/man-pages/man2/open_how.2type.html>
330+
/// # Reference
331+
///
332+
/// * [Linux](https://man7.org/linux/man-pages/man2/open_how.2type.html)
330333
#[repr(transparent)]
331334
#[derive(Clone, Copy, Debug)]
332335
pub struct OpenHow(libc::open_how);
@@ -666,8 +669,9 @@ pub fn readlink<P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
666669

667670
/// Read value of a symbolic link.
668671
///
669-
/// Equivalent to [`readlink` ] except where `path` specifies a relative path. In that case,
670-
/// interpret `path` relative to open file specified by `dirfd`.
672+
/// Equivalent to [`readlink` ] except for the case where `path` specifies a
673+
/// relative path, `path` will be interpreted relative to the path specified
674+
/// by `dirfd`. (Use [`AT_FDCWD`] to make it relative to the working directory).
671675
///
672676
/// # See Also
673677
/// * [`readlink`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html)

src/sys/stat.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ pub enum FchmodatFlags {
292292
///
293293
/// The file to be changed is determined relative to the directory associated
294294
/// with the file descriptor `dirfd` or the current working directory
295-
/// if `dirfd` is `None`.
295+
/// if `dirfd` is [`AT_FDCWD`](crate::fcntl::AT_FDCWD).
296296
///
297297
/// If `flag` is `FchmodatFlags::NoFollowSymlink` and `path` names a symbolic link,
298298
/// then the mode of the symbolic link is changed.
299299
///
300-
/// `fchmodat(None, path, mode, FchmodatFlags::FollowSymlink)` is identical to
300+
/// `fchmodat(AT_FDCWD, path, mode, FchmodatFlags::FollowSymlink)` is identical to
301301
/// a call `libc::chmod(path, mode)`. That's why `chmod` is unimplemented
302302
/// in the `nix` crate.
303303
///
@@ -416,12 +416,12 @@ pub enum UtimensatFlags {
416416
///
417417
/// The file to be changed is determined relative to the directory associated
418418
/// with the file descriptor `dirfd` or the current working directory
419-
/// if `dirfd` is `None`.
419+
/// if `dirfd` is [`AT_FDCWD`](crate::fcntl::AT_FDCWD).
420420
///
421421
/// If `flag` is `UtimensatFlags::NoFollowSymlink` and `path` names a symbolic link,
422422
/// then the mode of the symbolic link is changed.
423423
///
424-
/// `utimensat(None, path, times, UtimensatFlags::FollowSymlink)` is identical to
424+
/// `utimensat(AT_FDCWD, path, times, UtimensatFlags::FollowSymlink)` is identical to
425425
/// `utimes(path, times)`. The latter is a deprecated API so prefer using the
426426
/// former if the platforms you care about support it.
427427
///
@@ -458,17 +458,25 @@ pub fn utimensat<Fd: std::os::fd::AsFd, P: ?Sized + NixPath>(
458458
Errno::result(res).map(drop)
459459
}
460460

461+
/// Create a directory at the path specified by `dirfd` and `path`.
462+
///
463+
/// If `path` is a relative path, then it is interpreted relative to the directory
464+
/// referred to by the file descriptor `dirfd`. (One can use [`AT_FDCWD`][link] to
465+
/// specify the current working directory in `dirfd`). If `path` is absolute,
466+
/// then `dirfd` is ignored.
467+
///
468+
/// [link]: crate::fcntl::AT_FDCWD
461469
#[cfg(not(target_os = "redox"))]
462470
pub fn mkdirat<Fd: std::os::fd::AsFd, P: ?Sized + NixPath>(
463-
fd: Fd,
471+
dirfd: Fd,
464472
path: &P,
465473
mode: Mode,
466474
) -> Result<()> {
467475
use std::os::fd::AsRawFd;
468476

469477
let res = path.with_nix_path(|cstr| unsafe {
470478
libc::mkdirat(
471-
fd.as_fd().as_raw_fd(),
479+
dirfd.as_fd().as_raw_fd(),
472480
cstr.as_ptr(),
473481
mode.bits() as mode_t,
474482
)

src/unistd.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: crate::sys::stat::Mode) -> Res
773773
Errno::result(res).map(drop)
774774
}
775775

776-
/// Creates new fifo special file (named pipe) with path `path` and access rights `mode`.
776+
/// Creates new FIFO special file (named pipe) with path `path` and access rights `mode`.
777777
///
778778
/// # Errors
779779
///
@@ -812,7 +812,8 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: crate::sys::stat::Mode) -> Re
812812
Errno::result(res).map(drop)
813813
}
814814

815-
/// Creates new fifo special file (named pipe) with path `path` and access rights `mode`.
815+
/// Creates new FIFO special file (named pipe) with access rights set to `mode`
816+
/// in the path specified by `dirfd` and `path`.
816817
///
817818
/// # Examples
818819
///
@@ -851,11 +852,12 @@ pub fn mkfifoat<Fd: std::os::fd::AsFd, P: ?Sized + NixPath>(
851852
Errno::result(res).map(drop)
852853
}
853854

854-
/// Creates a symbolic link at `path2` which points to `path1`.
855+
/// Creates a symbolic link to `path1` in the path specified by `dirfd` and
856+
/// `path2`.
855857
///
856858
/// # Examples
857859
///
858-
/// Assume file foo exists in the current working directory, create a symlink
860+
/// Assume file `foo` exists in the current working directory, create a symlink
859861
/// to it:
860862
///
861863
/// ```no_run
@@ -1585,9 +1587,10 @@ impl LinkatFlags {
15851587
/// Creates a new hard link (directory entry) at `newpath` for the existing file
15861588
/// at `oldpath`. In the case of a relative `oldpath`, the path is interpreted
15871589
/// relative to the directory associated with file descriptor `olddirfd` instead
1588-
/// of the current working directory and similarly for `newpath` and file
1589-
/// descriptor `newdirfd`. If either `oldpath` or `newpath` is absolute, then
1590-
/// `dirfd` is ignored.
1590+
/// of the current working directory, use [`AT_FDCWD`](crate::fcntl::AT_FDCWD)
1591+
/// if you want to make it relative to the current working directory. Similarly
1592+
/// for `newpath` and file descriptor `newdirfd`. If either `oldpath` or `newpath`
1593+
/// is absolute, then `dirfd` is ignored.
15911594
///
15921595
/// In case `flag` is `AtFlags::AT_SYMLINK_FOLLOW` and `oldpath` names a symoblic
15931596
/// link, a new link for the target of the symbolic link is created.
@@ -1639,10 +1642,12 @@ pub enum UnlinkatFlags {
16391642
/// Remove a directory entry
16401643
///
16411644
/// In the case of a relative path, the directory entry to be removed is determined
1642-
/// relative to the directory associated with the file descriptor `dirfd`. In the
1643-
/// case of an absolute `path` `dirfd` is ignored. If `flag` is
1644-
/// `UnlinkatFlags::RemoveDir` then removal of the directory entry specified by
1645-
/// `dirfd` and `path` is performed.
1645+
/// relative to the directory associated with the file descriptor `dirfd` (Use
1646+
/// [`AT_FDCWD`](crate::fcntl::AT_FDCWD) if you want to specify the current working
1647+
/// directory in `dirfd`). In the case of an absolute path, `dirfd` is ignored.
1648+
///
1649+
/// If `flag` is `UnlinkatFlags::RemoveDir` then removal of the directory entry
1650+
/// specified by `dirfd` and `path` is performed.
16461651
///
16471652
/// # References
16481653
/// See also [unlinkat(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html)

0 commit comments

Comments
 (0)