@@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashMap;
88use rustc_middle:: ty:: layout:: LayoutOf ;
99use rustc_target:: abi:: Size ;
1010
11+ use crate :: helpers:: target_os_is_unix;
1112use crate :: * ;
1213
1314/// Check whether an operation that writes to a target buffer was successful.
@@ -55,7 +56,7 @@ impl<'tcx> EnvVars<'tcx> {
5556 } ;
5657 if forward {
5758 let var_ptr = match target_os {
58- "linux" | "macos" =>
59+ target if target_os_is_unix ( target ) =>
5960 alloc_env_var_as_c_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ?,
6061 "windows" => alloc_env_var_as_wide_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ?,
6162 unsupported =>
@@ -113,11 +114,7 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
113114pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
114115 fn getenv ( & mut self , name_op : & OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , Pointer < Option < Tag > > > {
115116 let this = self . eval_context_mut ( ) ;
116- let target_os = & this. tcx . sess . target . os ;
117- assert ! (
118- target_os == "linux" || target_os == "macos" ,
119- "`getenv` is only available for the UNIX target family"
120- ) ;
117+ this. assert_target_os_is_unix ( "getenv" ) ;
121118
122119 let name_ptr = this. read_pointer ( name_op) ?;
123120 let name = this. read_os_str_from_c_str ( name_ptr) ?;
@@ -211,11 +208,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
211208 value_op : & OpTy < ' tcx , Tag > ,
212209 ) -> InterpResult < ' tcx , i32 > {
213210 let this = self . eval_context_mut ( ) ;
214- let target_os = & this. tcx . sess . target . os ;
215- assert ! (
216- target_os == "linux" || target_os == "macos" ,
217- "`setenv` is only available for the UNIX target family"
218- ) ;
211+ this. assert_target_os_is_unix ( "setenv" ) ;
219212
220213 let name_ptr = this. read_pointer ( name_op) ?;
221214 let value_ptr = this. read_pointer ( value_op) ?;
@@ -285,11 +278,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
285278
286279 fn unsetenv ( & mut self , name_op : & OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , i32 > {
287280 let this = self . eval_context_mut ( ) ;
288- let target_os = & this. tcx . sess . target . os ;
289- assert ! (
290- target_os == "linux" || target_os == "macos" ,
291- "`unsetenv` is only available for the UNIX target family"
292- ) ;
281+ this. assert_target_os_is_unix ( "unsetenv" ) ;
293282
294283 let name_ptr = this. read_pointer ( name_op) ?;
295284 let mut success = None ;
@@ -319,11 +308,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
319308 size_op : & OpTy < ' tcx , Tag > ,
320309 ) -> InterpResult < ' tcx , Pointer < Option < Tag > > > {
321310 let this = self . eval_context_mut ( ) ;
322- let target_os = & this. tcx . sess . target . os ;
323- assert ! (
324- target_os == "linux" || target_os == "macos" ,
325- "`getcwd` is only available for the UNIX target family"
326- ) ;
311+ this. assert_target_os_is_unix ( "getcwd" ) ;
327312
328313 let buf = this. read_pointer ( buf_op) ?;
329314 let size = this. read_scalar ( size_op) ?. to_machine_usize ( & * this. tcx ) ?;
@@ -378,11 +363,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
378363
379364 fn chdir ( & mut self , path_op : & OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , i32 > {
380365 let this = self . eval_context_mut ( ) ;
381- let target_os = & this. tcx . sess . target . os ;
382- assert ! (
383- target_os == "linux" || target_os == "macos" ,
384- "`chdir` is only available for the UNIX target family"
385- ) ;
366+ this. assert_target_os_is_unix ( "chdir" ) ;
386367
387368 let path = this. read_path_from_c_str ( this. read_pointer ( path_op) ?) ?;
388369
@@ -468,11 +449,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
468449
469450 fn getpid ( & mut self ) -> InterpResult < ' tcx , i32 > {
470451 let this = self . eval_context_mut ( ) ;
471- let target_os = & this. tcx . sess . target . os ;
472- assert ! (
473- target_os == "linux" || target_os == "macos" ,
474- "`getpid` is only available for the UNIX target family"
475- ) ;
452+ this. assert_target_os_is_unix ( "getpid" ) ;
476453
477454 this. check_no_isolation ( "`getpid`" ) ?;
478455
0 commit comments