提交 ce00b3e2 编写于 作者: D Dan Gohman

Use `link` on platforms which lack `linkat`.

上级 23a5c214
......@@ -1067,10 +1067,20 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
let src = cstr(src)?;
let dst = cstr(dst)?;
// Use `linkat` with `AT_FDCWD` instead of `link` as `link` leaves it
// implementation-defined whether it follows symlinks. Pass 0 as the
// `linkat` flags argument so that we don't follow symlinks.
cvt(unsafe { libc::linkat(libc::AT_FDCWD, src.as_ptr(), libc::AT_FDCWD, dst.as_ptr(), 0) })?;
cfg_if::cfg_if! {
if #[cfg(any(target_os = "vxworks", target_os = "redox"))] {
// VxWorks and Redox lack `linkat`, so use `link` instead. POSIX
// leaves it implementation-defined whether `link` follows symlinks,
// so rely on the `symlink_hard_link` test in
// library/std/src/fs/tests.rs to check the behavior.
cvt(unsafe { libc::link(src.as_ptr(), dst.as_ptr()) })?;
} else {
// Use `linkat` with `AT_FDCWD` instead of `link` as `linkat` gives
// us a flag to specify how symlinks should be handled. Pass 0 as
// the flags argument, meaning don't follow symlinks.
cvt(unsafe { libc::linkat(libc::AT_FDCWD, src.as_ptr(), libc::AT_FDCWD, dst.as_ptr(), 0) })?;
}
}
Ok(())
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册