summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <johannes.schindelin@gmx.de>2018-10-15 02:47:05 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-10-16 12:59:57 +0900
commit55b6513e730126ce5512a83d2e00dea30971a523 (patch)
tree0fb208c3ba1329d40acc20bcc0ebcb5da623db89 /compat
parentGit 2.19.1 (diff)
downloadtgif-55b6513e730126ce5512a83d2e00dea30971a523.tar.xz
getpwuid(mingw): initialize the structure only once
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/mingw.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 858ca14a57..32fa6e7c1f 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1770,16 +1770,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;
+ DWORD len;
- DWORD len = sizeof(user_name);
- if (!GetUserName(user_name, &len))
+ if (initialized)
+ return p;
+
+ len = sizeof(user_name);
+ if (!GetUserName(user_name, &len)) {
+ initialized = 1;
return NULL;
- p.pw_name = user_name;
- p.pw_gecos = "unknown";
- p.pw_dir = NULL;
- return &p;
+ }
+
+ p = xmalloc(sizeof(*p));
+ p->pw_name = user_name;
+ p->pw_gecos = "unknown";
+ p->pw_dir = NULL;
+
+ initialized = 1;
+ return p;
}
static HANDLE timer_event;