diff options
author | oblique <psyberbits@gmail.com> | 2018-12-11 23:32:09 +0200 |
---|---|---|
committer | oblique <psyberbits@gmail.com> | 2018-12-12 00:49:15 +0200 |
commit | 98ac44103601cdf0578f868e12f3090051dabe5f (patch) | |
tree | 575126a951c965eb43e78256dedfb4357938cec3 /test/test_unistd.rs | |
parent | f1b12d6b1b8bf6d8ad41e7b2967b95c6f876745c (diff) | |
download | nix-98ac44103601cdf0578f868e12f3090051dabe5f.zip |
Implement symlinkat
Diffstat (limited to 'test/test_unistd.rs')
-rw-r--r-- | test/test_unistd.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs index a4bb92eb..8b373278 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1,4 +1,4 @@ -use nix::fcntl::{fcntl, FcntlArg, FdFlag, open, OFlag}; +use nix::fcntl::{fcntl, FcntlArg, FdFlag, open, OFlag, readlink}; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction}; @@ -543,3 +543,29 @@ fn test_canceling_alarm() { assert_eq!(alarm::set(60), None); assert_eq!(alarm::cancel(), Some(60)); } + +#[test] +fn test_symlinkat() { + let mut buf = [0; 1024]; + let tempdir = tempfile::tempdir().unwrap(); + + let target = tempdir.path().join("a"); + let linkpath = tempdir.path().join("b"); + symlinkat(&target, None, &linkpath).unwrap(); + assert_eq!( + readlink(&linkpath, &mut buf).unwrap().to_str().unwrap(), + target.to_str().unwrap() + ); + + let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap(); + let target = "c"; + let linkpath = "d"; + symlinkat(target, Some(dirfd), linkpath).unwrap(); + assert_eq!( + readlink(&tempdir.path().join(linkpath), &mut buf) + .unwrap() + .to_str() + .unwrap(), + target + ); +} |