@@ -10,6 +10,21 @@ use rustc_data_structures::fx::FxHashMap;
1010use rustc:: ty:: layout:: Size ;
1111use rustc_mir:: interpret:: Pointer ;
1212
13+ /// Check whether an operation that writes to a target buffer was successful.
14+ /// Accordingly select return value.
15+ /// Local helper function to be used in Windows shims.
16+ fn windows_check_buffer_size ( ( success, len) : ( bool , u64 ) ) -> u32 {
17+ if success {
18+ // If the function succeeds, the return value is the number of characters stored in the target buffer,
19+ // not including the terminating null character.
20+ u32:: try_from ( len) . unwrap ( )
21+ } else {
22+ // If the target buffer was not large enough to hold the data, the return value is the buffer size, in characters,
23+ // required to hold the string and its terminating null character.
24+ u32:: try_from ( len. checked_add ( 1 ) . unwrap ( ) ) . unwrap ( )
25+ }
26+ }
27+
1328#[ derive( Default ) ]
1429pub struct EnvVars < ' tcx > {
1530 /// Stores pointers to the environment variables. These variables must be stored as
@@ -399,18 +414,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
399414 Ok ( ( ) )
400415 }
401416}
402-
403- /// Check whether an operation that writes to a target buffer was successful.
404- /// Accordingly select return value.
405- /// Local helper function to be used in Windows shims.
406- fn windows_check_buffer_size ( ( success, len) : ( bool , u64 ) ) -> u32 {
407- if success {
408- // If the function succeeds, the return value is the number of characters stored in the target buffer,
409- // not including the terminating null character.
410- u32:: try_from ( len) . unwrap ( )
411- } else {
412- // If the target buffer was not large enough to hold the data, the return value is the buffer size, in characters,
413- // required to hold the string and its terminating null character.
414- u32:: try_from ( len. checked_add ( 1 ) . unwrap ( ) ) . unwrap ( )
415- }
416- }
0 commit comments