diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-12 14:59:21 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-12 14:59:21 +0000 |
commit | 51bd0859aa4826687b48e141ee83d9d12f96e7e2 (patch) | |
tree | 575126a951c965eb43e78256dedfb4357938cec3 /src/unistd.rs | |
parent | f1b12d6b1b8bf6d8ad41e7b2967b95c6f876745c (diff) | |
parent | 98ac44103601cdf0578f868e12f3090051dabe5f (diff) | |
download | nix-51bd0859aa4826687b48e141ee83d9d12f96e7e2.zip |
Merge #997
997: Implement symlinkat r=asomers a=oblique
Co-authored-by: oblique <psyberbits@gmail.com>
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index f2ad55b2..2c00f7f0 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -506,6 +506,34 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> { Errno::result(res).map(drop) } +/// Creates a symbolic link at `path2` which points to `path1`. +/// +/// If `dirfd` has a value, then `path2` is relative to directory associated +/// with the file descriptor. +/// +/// If `dirfd` is `None`, then `path2` is relative to the current working +/// directory. This is identical to `libc::symlink(path1, path2)`. +/// +/// See also [symlinkat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlinkat.html). +pub fn symlinkat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>( + path1: &P1, + dirfd: Option<RawFd>, + path2: &P2) -> Result<()> { + let res = + path1.with_nix_path(|path1| { + path2.with_nix_path(|path2| { + unsafe { + libc::symlinkat( + path1.as_ptr(), + dirfd.unwrap_or(libc::AT_FDCWD), + path2.as_ptr() + ) + } + }) + })??; + Errno::result(res).map(drop) +} + /// Returns the current directory as a `PathBuf` /// /// Err is returned if the current user doesn't have the permission to read or search a component |