@@ -2629,7 +2629,7 @@ pub struct User {
26292629 /// Group ID
26302630 pub gid : Gid ,
26312631 /// User information
2632- #[ cfg( not( target_os = "android" ) ) ]
2632+ #[ cfg( not( all ( target_os = "android" , target_pointer_width = "32" ) ) ) ]
26332633 pub gecos : CString ,
26342634 /// Home directory
26352635 pub dir : PathBuf ,
@@ -2665,7 +2665,7 @@ impl From<&libc::passwd> for User {
26652665 User {
26662666 name : CStr :: from_ptr ( ( * pw) . pw_name ) . to_string_lossy ( ) . into_owned ( ) ,
26672667 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" ) ) ) ]
26692669 gecos : CString :: new ( CStr :: from_ptr ( ( * pw) . pw_gecos ) . to_bytes ( ) ) . unwrap ( ) ,
26702670 dir : PathBuf :: from ( OsStr :: from_bytes ( CStr :: from_ptr ( ( * pw) . pw_dir ) . to_bytes ( ) ) ) ,
26712671 shell : PathBuf :: from ( OsStr :: from_bytes ( CStr :: from_ptr ( ( * pw) . pw_shell ) . to_bytes ( ) ) ) ,
@@ -2694,6 +2694,58 @@ impl From<&libc::passwd> for User {
26942694 }
26952695}
26962696
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+
26972749#[ cfg( not( target_os = "redox" ) ) ] // RedoxFS does not support passwd
26982750impl User {
26992751 fn from_anything < F > ( f : F ) -> Result < Option < Self > >
0 commit comments