diff --git a/src/uu/pwdx/Cargo.toml b/src/uu/pwdx/Cargo.toml new file mode 100644 index 0000000..7dae65d --- /dev/null +++ b/src/uu/pwdx/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "uu_pwdx" +version = "0.0.1" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[[bin]] +name = "pwdx" +path = "src/pwdx.rs" diff --git a/src/uu/pwdx/src/pwdx.rs b/src/uu/pwdx/src/pwdx.rs new file mode 100644 index 0000000..872f2b2 --- /dev/null +++ b/src/uu/pwdx/src/pwdx.rs @@ -0,0 +1,24 @@ +use std::env; +use std::fs; +use std::path::Path; +use std::process; + +fn main() { + let args: Vec<String> = env::args().collect(); + + if args.len() != 2 { + eprintln!("Usage: pwdx <pid>"); + process::exit(1); + } + + let pid = &args[1]; + let cwd_link = format!("/proc/{}/cwd", pid); + + match fs::read_link(Path::new(&cwd_link)) { + Ok(path) => println!("{}: {}", pid, path.display()), + Err(e) => { + eprintln!("pwdx: failed to read link for PID {}: {}", pid, e); + process::exit(1); + } + } +}