@@ -19,12 +19,20 @@ use {
19
19
use alloc:: { string:: String , string:: ToString , vec:: Vec } ;
20
20
use cstr_core:: CString ;
21
21
22
+ #[ cfg( target_os = "linux" ) ]
22
23
extern "C" {
23
24
pub fn _frida_g_get_home_dir ( ) -> * const c_char ;
24
25
pub fn _frida_g_get_current_dir ( ) -> * const c_char ;
25
26
pub fn _frida_g_get_tmp_dir ( ) -> * const c_char ;
26
27
}
27
28
29
+ #[ cfg( not( target_os = "linux" ) ) ]
30
+ extern "C" {
31
+ pub fn _g_get_home_dir ( ) -> * const c_char ;
32
+ pub fn _g_get_current_dir ( ) -> * const c_char ;
33
+ pub fn _g_get_tmp_dir ( ) -> * const c_char ;
34
+ }
35
+
28
36
#[ derive( Clone , FromPrimitive , Debug ) ]
29
37
#[ repr( u32 ) ]
30
38
pub enum CodeSigningPolicy {
@@ -121,27 +129,36 @@ impl<'a> Process<'a> {
121
129
/// Returns a string specifying the filesystem path to the current working directory
122
130
pub fn current_dir ( & self ) -> String {
123
131
unsafe {
124
- CStr :: from_ptr ( _frida_g_get_current_dir ( ) )
125
- . to_string_lossy ( )
126
- . to_string ( )
132
+ #[ cfg( target_os = "linux" ) ]
133
+ let dir = _frida_g_get_current_dir ( ) ;
134
+ #[ cfg( not( target_os = "linux" ) ) ]
135
+ let dir = _g_get_current_dir ( ) ;
136
+
137
+ CStr :: from_ptr ( dir) . to_string_lossy ( ) . to_string ( )
127
138
}
128
139
}
129
140
130
141
/// Returns a string specifying the filesystem path to the directory to use for temporary files
131
142
pub fn tmp_dir ( & self ) -> String {
132
143
unsafe {
133
- CStr :: from_ptr ( _frida_g_get_tmp_dir ( ) )
134
- . to_string_lossy ( )
135
- . to_string ( )
144
+ #[ cfg( target_os = "linux" ) ]
145
+ let dir = _frida_g_get_tmp_dir ( ) ;
146
+ #[ cfg( not( target_os = "linux" ) ) ]
147
+ let dir = _g_get_tmp_dir ( ) ;
148
+
149
+ CStr :: from_ptr ( dir) . to_string_lossy ( ) . to_string ( )
136
150
}
137
151
}
138
152
139
153
/// Returns a string specifying the filesystem path to the current user’s home directory
140
154
pub fn home_dir ( & self ) -> String {
141
155
unsafe {
142
- CStr :: from_ptr ( _frida_g_get_home_dir ( ) )
143
- . to_string_lossy ( )
144
- . to_string ( )
156
+ #[ cfg( target_os = "linux" ) ]
157
+ let dir = _frida_g_get_home_dir ( ) ;
158
+ #[ cfg( not( target_os = "linux" ) ) ]
159
+ let dir = _g_get_home_dir ( ) ;
160
+
161
+ CStr :: from_ptr ( dir) . to_string_lossy ( ) . to_string ( )
145
162
}
146
163
}
147
164
0 commit comments