Skip to content

Commit e77ecab

Browse files
committed
mkfifo: replace unsafe libc::mkfifo with nix::unistd::mkfifo
1 parent 20a5c3a commit e77ecab

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

Cargo.lock

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

src/uu/mkfifo/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ path = "src/mkfifo.rs"
2020
[dependencies]
2121
clap = { workspace = true }
2222
libc = { workspace = true }
23+
nix = { workspace = true, features = ["fs"] }
2324
uucore = { workspace = true, features = ["fs", "mode"] }
2425
fluent = { workspace = true }
2526

src/uu/mkfifo/src/mkfifo.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// file that was distributed with this source code.
55

66
use clap::{Arg, ArgAction, Command, value_parser};
7-
use libc::mkfifo;
8-
use std::ffi::CString;
7+
use nix::sys::stat::Mode;
8+
use nix::unistd::mkfifo;
99
use std::fs;
1010
use std::os::unix::fs::PermissionsExt;
1111
use uucore::display::Quotable;
@@ -39,11 +39,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3939
};
4040

4141
for f in fifos {
42-
let err = unsafe {
43-
let name = CString::new(f.as_bytes()).unwrap();
44-
mkfifo(name.as_ptr(), 0o666)
45-
};
46-
if err == -1 {
42+
if mkfifo(f.as_str(), Mode::from_bits_truncate(0o666)).is_err() {
4743
show!(USimpleError::new(
4844
1,
4945
translate!("mkfifo-error-cannot-create-fifo", "path" => f.quote()),

0 commit comments

Comments
 (0)