@@ -1915,18 +1915,63 @@ int mingw_getpagesize(void)
19151915 return si .dwAllocationGranularity ;
19161916}
19171917
1918+ /* See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx */
1919+ enum EXTENDED_NAME_FORMAT {
1920+ NameDisplay = 3 ,
1921+ NameUserPrincipal = 8
1922+ };
1923+
1924+ static char * get_extended_user_info (enum EXTENDED_NAME_FORMAT type )
1925+ {
1926+ DECLARE_PROC_ADDR (secur32 .dll , BOOL , GetUserNameExW ,
1927+ enum EXTENDED_NAME_FORMAT , LPCWSTR , PULONG );
1928+ static wchar_t wbuffer [1024 ];
1929+ DWORD len ;
1930+
1931+ if (!INIT_PROC_ADDR (GetUserNameExW ))
1932+ return NULL ;
1933+
1934+ len = ARRAY_SIZE (wbuffer );
1935+ if (GetUserNameExW (type , wbuffer , & len )) {
1936+ char * converted = xmalloc ((len *= 3 ));
1937+ if (xwcstoutf (converted , wbuffer , len ) >= 0 )
1938+ return converted ;
1939+ free (converted );
1940+ }
1941+
1942+ return NULL ;
1943+ }
1944+
1945+ char * mingw_query_user_email (void )
1946+ {
1947+ return get_extended_user_info (NameUserPrincipal );
1948+ }
1949+
19181950struct passwd * getpwuid (int uid )
19191951{
1952+ static unsigned initialized ;
19201953 static char user_name [100 ];
1921- static struct passwd p ;
1954+ static struct passwd * p ;
1955+ DWORD len ;
1956+
1957+ if (initialized )
1958+ return p ;
19221959
1923- DWORD len = sizeof (user_name );
1924- if (!GetUserName (user_name , & len ))
1960+ len = sizeof (user_name );
1961+ if (!GetUserName (user_name , & len )) {
1962+ initialized = 1 ;
19251963 return NULL ;
1926- p .pw_name = user_name ;
1927- p .pw_gecos = "unknown" ;
1928- p .pw_dir = NULL ;
1929- return & p ;
1964+ }
1965+
1966+ p = xmalloc (sizeof (* p ));
1967+ p -> pw_name = user_name ;
1968+ p -> pw_gecos = get_extended_user_info (NameDisplay );
1969+ if (!p -> pw_gecos )
1970+ p -> pw_gecos = "unknown" ;
1971+ p -> pw_dir = NULL ;
1972+
1973+ initialized = 1 ;
1974+ return p ;
19301975}
19311976
19321977static HANDLE timer_event ;
0 commit comments