@@ -409,10 +409,9 @@ pub unsafe fn environ() -> *mut *const *const c_char {
409
409
/// environment variables of the current process.
410
410
pub fn env ( ) -> Env {
411
411
unsafe {
412
- ENV_LOCK . lock ( ) ;
412
+ let _guard = ENV_LOCK . lock ( ) ;
413
413
let mut environ = * environ ( ) ;
414
414
if environ == ptr:: null ( ) {
415
- ENV_LOCK . unlock ( ) ;
416
415
panic ! ( "os::env() failure getting env string from OS: {}" ,
417
416
io:: Error :: last_os_error( ) ) ;
418
417
}
@@ -423,12 +422,10 @@ pub fn env() -> Env {
423
422
}
424
423
environ = environ. offset ( 1 ) ;
425
424
}
426
- let ret = Env {
425
+ return Env {
427
426
iter : result. into_iter ( ) ,
428
427
_dont_send_or_sync_me : PhantomData ,
429
- } ;
430
- ENV_LOCK . unlock ( ) ;
431
- return ret
428
+ }
432
429
}
433
430
434
431
fn parse ( input : & [ u8 ] ) -> Option < ( OsString , OsString ) > {
@@ -452,15 +449,14 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
452
449
// always None as well
453
450
let k = CString :: new ( k. as_bytes ( ) ) ?;
454
451
unsafe {
455
- ENV_LOCK . lock ( ) ;
452
+ let _guard = ENV_LOCK . lock ( ) ;
456
453
let s = libc:: getenv ( k. as_ptr ( ) ) as * const libc:: c_char ;
457
454
let ret = if s. is_null ( ) {
458
455
None
459
456
} else {
460
457
Some ( OsStringExt :: from_vec ( CStr :: from_ptr ( s) . to_bytes ( ) . to_vec ( ) ) )
461
458
} ;
462
- ENV_LOCK . unlock ( ) ;
463
- return Ok ( ret)
459
+ Ok ( ret)
464
460
}
465
461
}
466
462
@@ -469,21 +465,17 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
469
465
let v = CString :: new ( v. as_bytes ( ) ) ?;
470
466
471
467
unsafe {
472
- ENV_LOCK . lock ( ) ;
473
- let ret = cvt ( libc:: setenv ( k. as_ptr ( ) , v. as_ptr ( ) , 1 ) ) . map ( |_| ( ) ) ;
474
- ENV_LOCK . unlock ( ) ;
475
- return ret
468
+ let _guard = ENV_LOCK . lock ( ) ;
469
+ cvt ( libc:: setenv ( k. as_ptr ( ) , v. as_ptr ( ) , 1 ) ) . map ( |_| ( ) )
476
470
}
477
471
}
478
472
479
473
pub fn unsetenv ( n : & OsStr ) -> io:: Result < ( ) > {
480
474
let nbuf = CString :: new ( n. as_bytes ( ) ) ?;
481
475
482
476
unsafe {
483
- ENV_LOCK . lock ( ) ;
484
- let ret = cvt ( libc:: unsetenv ( nbuf. as_ptr ( ) ) ) . map ( |_| ( ) ) ;
485
- ENV_LOCK . unlock ( ) ;
486
- return ret
477
+ let _guard = ENV_LOCK . lock ( ) ;
478
+ cvt ( libc:: unsetenv ( nbuf. as_ptr ( ) ) ) . map ( |_| ( ) )
487
479
}
488
480
}
489
481
0 commit comments