draft of pwdx

This commit is contained in:
Sylvestre Ledru 2024-01-16 19:10:20 +01:00
parent 8bba913e56
commit 7163749b04
2 changed files with 36 additions and 0 deletions
src/uu/pwdx

12
src/uu/pwdx/Cargo.toml Normal file

@ -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"

24
src/uu/pwdx/src/pwdx.rs Normal file

@ -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);
}
}
}