@@ -2629,7 +2629,7 @@ pub struct User {
2629
2629
/// Group ID
2630
2630
pub gid : Gid ,
2631
2631
/// User information
2632
- #[ cfg( not( target_os = "android" ) ) ]
2632
+ #[ cfg( not( all ( target_os = "android" , target_pointer_width = "32" ) ) ) ]
2633
2633
pub gecos : CString ,
2634
2634
/// Home directory
2635
2635
pub dir : PathBuf ,
@@ -2665,7 +2665,7 @@ impl From<&libc::passwd> for User {
2665
2665
User {
2666
2666
name : CStr :: from_ptr ( ( * pw) . pw_name ) . to_string_lossy ( ) . into_owned ( ) ,
2667
2667
passwd : CString :: new ( CStr :: from_ptr ( ( * pw) . pw_passwd ) . to_bytes ( ) ) . unwrap ( ) ,
2668
- #[ cfg( not( target_os = "android" ) ) ]
2668
+ #[ cfg( not( all ( target_os = "android" , target_pointer_width = "32" ) ) ) ]
2669
2669
gecos : CString :: new ( CStr :: from_ptr ( ( * pw) . pw_gecos ) . to_bytes ( ) ) . unwrap ( ) ,
2670
2670
dir : PathBuf :: from ( OsStr :: from_bytes ( CStr :: from_ptr ( ( * pw) . pw_dir ) . to_bytes ( ) ) ) ,
2671
2671
shell : PathBuf :: from ( OsStr :: from_bytes ( CStr :: from_ptr ( ( * pw) . pw_shell ) . to_bytes ( ) ) ) ,
@@ -2694,6 +2694,58 @@ impl From<&libc::passwd> for User {
2694
2694
}
2695
2695
}
2696
2696
2697
+ #[ cfg( not( target_os = "redox" ) ) ] // RedoxFS does not support passwd
2698
+ impl From < User > for libc:: passwd {
2699
+ fn from ( u : User ) -> Self {
2700
+ let name = match CString :: new ( u. name ) {
2701
+ Ok ( n) => n. into_raw ( ) ,
2702
+ Err ( _) => CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
2703
+ } ;
2704
+ let dir = match u. dir . into_os_string ( ) . into_string ( ) {
2705
+ Ok ( s) => CString :: new ( s. as_str ( ) ) . unwrap ( ) . into_raw ( ) ,
2706
+ Err ( _) => CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
2707
+ } ;
2708
+ let shell = match u. shell . into_os_string ( ) . into_string ( ) {
2709
+ Ok ( s) => CString :: new ( s. as_str ( ) ) . unwrap ( ) . into_raw ( ) ,
2710
+ Err ( _) => CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
2711
+ } ;
2712
+ Self {
2713
+ pw_name : name,
2714
+ pw_passwd : u. passwd . into_raw ( ) ,
2715
+ #[ cfg( not( all( target_os = "android" , target_pointer_width = "32" ) ) ) ]
2716
+ pw_gecos : u. gecos . into_raw ( ) ,
2717
+ pw_dir : dir,
2718
+ pw_shell : shell,
2719
+ pw_uid : u. uid . 0 ,
2720
+ pw_gid : u. gid . 0 ,
2721
+ #[ cfg( not( any( target_os = "android" ,
2722
+ target_os = "fuchsia" ,
2723
+ target_os = "illumos" ,
2724
+ target_os = "linux" ,
2725
+ target_os = "solaris" ) ) ) ]
2726
+ pw_class : u. class . into_raw ( ) ,
2727
+ #[ cfg( not( any( target_os = "android" ,
2728
+ target_os = "fuchsia" ,
2729
+ target_os = "illumos" ,
2730
+ target_os = "linux" ,
2731
+ target_os = "solaris" ) ) ) ]
2732
+ pw_change : u. change ,
2733
+ #[ cfg( not( any( target_os = "android" ,
2734
+ target_os = "fuchsia" ,
2735
+ target_os = "illumos" ,
2736
+ target_os = "linux" ,
2737
+ target_os = "solaris" ) ) ) ]
2738
+ pw_expire : u. expire ,
2739
+ #[ cfg( target_os = "illumos" ) ]
2740
+ pw_age : CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
2741
+ #[ cfg( target_os = "illumos" ) ]
2742
+ pw_comment : CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
2743
+ #[ cfg( target_os = "freebsd" ) ]
2744
+ pw_fields : 0 ,
2745
+ }
2746
+ }
2747
+ }
2748
+
2697
2749
#[ cfg( not( target_os = "redox" ) ) ] // RedoxFS does not support passwd
2698
2750
impl User {
2699
2751
fn from_anything < F > ( f : F ) -> Result < Option < Self > >
0 commit comments