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

Re: [PATCH 1/3] getpwuid(mingw): initialize the structure only once

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 15, 2018, 14:25 UTC
Message-ID
<CAPig+cS3Bz3uaxWv23bQEXB7Ok=Q+V07mGc-Fysg-WU3DKKagA@mail.gmail.com>
In-Reply-To
<63373dd91d0be324273ab34ff49d630453954173.1539596822.git.gitgitgadget@gmail.com>

On Mon, Oct 15, 2018 at 5:47 AM Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 19 quoted lines
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> diff --git a/compat/mingw.c b/compat/mingw.c
> @@ -1800,16 +1800,27 @@ int mingw_getpagesize(void)
>  struct passwd *getpwuid(int uid)
>  {
> +       static unsigned initialized;
>         static char user_name[100];
> -       static struct passwd p;
> +       static struct passwd *p;
>
> +       if (initialized)
> +               return p;
> +
> +       len = sizeof(user_name);
> +       if (!GetUserName(user_name, &len)) {
> +               initialized = 1;
>                 return NULL;
> +       }

If GetUserName() fails, that failure is recorded (as "initialized=1" and 'p' is still NULL), so subsequent invocations just return NULL without doing any more work. Makes sense.

Show 8 quoted lines
> +       p = xmalloc(sizeof(*p));
> +       p->pw_name = user_name;
> +       p->pw_gecos = "unknown";
> +       p->pw_dir = NULL;
> +
> +       initialized = 1;
> +       return p;
>  }
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 3 of 12 in “Provide a useful default user ident on Windows”
  1. 0/3 Provide a useful default user ident on WindowsJohannes Schindelin via GitGitGadget, Oct 15, 2018
  2. 1/3 getpwuid(mingw): initialize the structure only onceJohannes Schindelin via GitGitGadget, Oct 15, 2018
  3. Eric SunshineOct 15, 2018
  4. 2/3 getpwuid(mingw): provide a better default for the user nameJohannes Schindelin via GitGitGadget, Oct 15, 2018
  5. Eric SunshineOct 15, 2018
  6. Johannes SchindelinOct 16, 2018
  7. Eric SunshineOct 16, 2018
  8. Johannes SchindelinOct 16, 2018
  9. 3/3 mingw: use domain information for default emailJohannes Schindelin via GitGitGadget, Oct 15, 2018
  10. Eric SunshineOct 15, 2018
  11. Johannes SchindelinOct 16, 2018
  12. Junio C HamanoOct 16, 2018

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.