git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] mingw: get pw_name in UTF-8 format

From
Beat Bolli <dev+git@drbeat.li>
Date
Jul 4, 2019, 20:13 UTC
Message-ID
<9bd9efde-8971-08f2-8417-1036286c9d1a@drbeat.li>
In-Reply-To
<54fff4ef40d1dba2153de27413fb53e992228b5b.1561628237.git.gitgitgadget@gmail.com>
On 27.06.19 11:37, Johannes Schindelin via GitGitGadget wrote:
Show 30 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> Previously, we would have obtained the user name encoded in whatever the
> current code page is.
> 
> Note: the "user name" here does not denote the full name but instead the
> short logon name.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  compat/mingw.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 9b6d2400e1..8526876262 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1946,13 +1946,19 @@ struct passwd *getpwuid(int uid)
>  	static unsigned initialized;
>  	static char user_name[100];
>  	static struct passwd *p;
> +	wchar_t buf[100];
>  	DWORD len;
>  
>  	if (initialized)
>  		return p;
>  
> -	len = sizeof(user_name);
> -	if (!GetUserName(user_name, &len)) {
> +	len = sizeof(buf);
I think this should be "len = sizeof(buf) / sizeof(buf[0])".
GetUserNameW() takes the number of characters, not bytes.
Show 10 quoted lines
> +	if (!GetUserNameW(buf, &len)) {
> +		initialized = 1;
> +		return NULL;
> +	}
> +
> +	if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
>  		initialized = 1;
>  		return NULL;
>  	}
> 

Cheers, Beat

Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 3 of 8 in “Let's use the Win32 API more precisely”
  1. 0/2 Let's use the Win32 API more preciselyJohannes Schindelin via GitGitGadget, Jun 27, 2019
  2. 1/2 mingw: get pw_name in UTF-8 formatJohannes Schindelin via GitGitGadget, Jun 27, 2019
  3. Beat BolliJul 4, 2019
  4. Johannes SchindelinJul 4, 2019
  5. Beat BolliJul 4, 2019
  6. 2/2 mingw: use Unicode functions explicitlyJohannes Schindelin via GitGitGadget, Jun 27, 2019
  7. Eric SunshineJun 27, 2019
  8. Johannes SchindelinJun 27, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.