summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/fs/abs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/fs/abs.rs')
-rw-r--r--vendor/rustix/src/fs/abs.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs
index 81e991772..f57bd00fe 100644
--- a/vendor/rustix/src/fs/abs.rs
+++ b/vendor/rustix/src/fs/abs.rs
@@ -1,7 +1,6 @@
//! POSIX-style filesystem functions which operate on bare paths.
use crate::fd::OwnedFd;
-use crate::ffi::{CStr, CString};
#[cfg(not(target_os = "espidf"))]
use crate::fs::Access;
#[cfg(not(any(
@@ -17,9 +16,15 @@ use crate::fs::StatFs;
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
use crate::fs::StatVfs;
use crate::fs::{Mode, OFlags, Stat};
-use crate::path::SMALL_PATH_BUFFER_SIZE;
+#[cfg(not(target_os = "wasi"))]
+use crate::ugid::{Gid, Uid};
use crate::{backend, io, path};
-use alloc::vec::Vec;
+#[cfg(feature = "alloc")]
+use {
+ crate::ffi::{CStr, CString},
+ crate::path::SMALL_PATH_BUFFER_SIZE,
+ alloc::vec::Vec,
+};
/// `open(path, oflags, mode)`—Opens a file.
///
@@ -101,11 +106,13 @@ pub fn lstat<P: path::Arg>(path: P) -> io::Result<Stat> {
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html
/// [Linux]: https://man7.org/linux/man-pages/man2/readlink.2.html
+#[cfg(feature = "alloc")]
#[inline]
pub fn readlink<P: path::Arg, B: Into<Vec<u8>>>(path: P, reuse: B) -> io::Result<CString> {
path.into_with_c_str(|path| _readlink(path, reuse.into()))
}
+#[cfg(feature = "alloc")]
fn _readlink(path: &CStr, mut buffer: Vec<u8>) -> io::Result<CString> {
// This code would benefit from having a better way to read into
// uninitialized memory, but that requires `unsafe`.
@@ -170,12 +177,21 @@ pub fn rmdir<P: path::Arg>(path: P) -> io::Result<()> {
/// `link(old_path, new_path)`—Creates a hard link.
///
+/// POSIX leaves it implementation-defined whether `link` follows a symlink in
+/// `old_path`, or creates a new link to the symbolic link itself. On platforms
+/// which have it, [`linkat`] avoids this problem since it has an [`AtFlags`]
+/// paramter and the [`AtFlags::SYMLINK_FOLLOW`] flag determines whether
+/// symlinks should be followed.
+///
/// # References
/// - [POSIX]
/// - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
/// [Linux]: https://man7.org/linux/man-pages/man2/link.2.html
+/// [`linkat`]: crate::fs::linkat
+/// [`AtFlags`]: crate::fs::AtFlags
+/// [`AtFlags::SYMLINK_FOLLOW`]: crate::fs::AtFlags::SYMLINK_FOLLOW
#[inline]
pub fn link<P: path::Arg, Q: path::Arg>(old_path: P, new_path: Q) -> io::Result<()> {
old_path.into_with_c_str(|old_path| {
@@ -266,3 +282,17 @@ pub fn statfs<P: path::Arg>(path: P) -> io::Result<StatFs> {
pub fn statvfs<P: path::Arg>(path: P) -> io::Result<StatVfs> {
path.into_with_c_str(backend::fs::syscalls::statvfs)
}
+
+/// `chown(path, owner, group)`—Sets open file or directory ownership.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/chown.2.html
+#[cfg(not(target_os = "wasi"))]
+#[inline]
+pub fn chown<P: path::Arg>(path: P, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> {
+ path.into_with_c_str(|path| backend::fs::syscalls::chown(path, owner, group))
+}