File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Concerning the current working directory of a process, from
2
+ //! `/proc/[pid]/cwd`.
3
+
4
+ use std:: fs;
5
+ use std:: io:: Result ;
6
+ use std:: path:: PathBuf ;
7
+
8
+ use libc:: pid_t;
9
+
10
+ /// Gets path of current working directory for the process with the provided
11
+ /// pid.
12
+ pub fn cwd ( pid : pid_t ) -> Result < PathBuf > {
13
+ fs:: read_link ( format ! ( "/proc/{}/cwd" , pid) )
14
+ }
15
+
16
+ /// Gets path of current working directory for the current process.
17
+ pub fn cwd_self ( ) -> Result < PathBuf > {
18
+ fs:: read_link ( "/proc/self/cwd" )
19
+ }
20
+
21
+ #[ cfg( test) ]
22
+ pub mod tests {
23
+ use super :: cwd_self;
24
+ use std:: env;
25
+
26
+ #[ test]
27
+ fn test_cwd_self ( ) {
28
+ assert_eq ! ( env:: current_dir( ) . unwrap( ) , cwd_self( ) . unwrap( ) ) ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change 1
1
//! Process-specific information from `/proc/[pid]/`.
2
2
3
+ mod cwd;
3
4
mod stat;
4
5
mod statm;
5
6
mod status;
6
7
8
+ pub use pid:: cwd:: { cwd, cwd_self} ;
7
9
pub use pid:: statm:: { Statm , statm, statm_self} ;
8
10
pub use pid:: status:: { SeccompMode , Status , status, status_self} ;
9
11
pub use pid:: stat:: { Stat } ;
You can’t perform that action at this time.
0 commit comments