Skip to content

Commit 8b311dd

Browse files
committed
ln: use rustix::fs::symlink instead of libc + CString on WASI
1 parent ea6e1d0 commit 8b311dd

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/ln/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path = "src/ln.rs"
2020

2121
[dependencies]
2222
clap = { workspace = true }
23-
libc = { workspace = true }
23+
rustix = { workspace = true, features = ["fs"] }
2424
uucore = { workspace = true, features = ["backup-control", "fs"] }
2525
thiserror = { workspace = true }
2626
fluent = { workspace = true }

src/uu/ln/src/ln.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use std::ffi::OsString;
1919
use std::fs;
2020
use thiserror::Error;
2121

22-
#[cfg(target_os = "wasi")]
23-
use std::ffi::CString;
2422
#[cfg(target_os = "wasi")]
2523
use std::io;
2624
#[cfg(any(unix, target_os = "redox"))]
@@ -495,16 +493,5 @@ pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> std::io::R
495493

496494
#[cfg(target_os = "wasi")]
497495
pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> io::Result<()> {
498-
use std::os::wasi::ffi::OsStrExt;
499-
500-
let src_c = CString::new(src.as_ref().as_os_str().as_bytes())
501-
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
502-
let dst_c = CString::new(dst.as_ref().as_os_str().as_bytes())
503-
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
504-
505-
if unsafe { libc::symlink(src_c.as_ptr(), dst_c.as_ptr()) } == 0 {
506-
Ok(())
507-
} else {
508-
Err(io::Error::last_os_error())
509-
}
496+
rustix::fs::symlink(src.as_ref(), dst.as_ref()).map_err(io::Error::from)
510497
}

0 commit comments

Comments
 (0)