Skip to content

Commit 48783ae

Browse files
committed
getpwuid(mingw): initialize the structure only once
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c65f515 commit 48783ae

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

compat/mingw.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,16 +1828,27 @@ int mingw_getpagesize(void)
18281828

18291829
struct passwd *getpwuid(int uid)
18301830
{
1831+
static unsigned initialized;
18311832
static char user_name[100];
1832-
static struct passwd p;
1833+
static struct passwd *p;
1834+
DWORD len;
1835+
1836+
if (initialized)
1837+
return p;
18331838

1834-
DWORD len = sizeof(user_name);
1835-
if (!GetUserName(user_name, &len))
1839+
len = sizeof(user_name);
1840+
if (!GetUserName(user_name, &len)) {
1841+
initialized = 1;
18361842
return NULL;
1837-
p.pw_name = user_name;
1838-
p.pw_gecos = "unknown";
1839-
p.pw_dir = NULL;
1840-
return &p;
1843+
}
1844+
1845+
p = xmalloc(sizeof(*p));
1846+
p->pw_name = user_name;
1847+
p->pw_gecos = "unknown";
1848+
p->pw_dir = NULL;
1849+
1850+
initialized = 1;
1851+
return p;
18411852
}
18421853

18431854
static HANDLE timer_event;

0 commit comments

Comments
 (0)