Skip to content

Commit

Permalink
testsuite: allow t/src/getpwuid.c to compile against musl
Browse files Browse the repository at this point in the history
Problem: musl libc doesn't have fgetpwent_r(3), so compilation of
t/src/getpwuid.c fails.

The program is not multithreaded, so switch to fgetpwent(3) and
getpwuid(3).
  • Loading branch information
grondo committed Nov 16, 2023
1 parent fd6f93b commit 6337aa0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions t/src/getpwuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@
struct passwd *getpwuid (uid_t uid)
{
const char *filename;
static char buf[4096];
static struct passwd pw;
struct passwd *pwp = NULL;

if ((filename = getenv ("TEST_PASSWD_FILE"))) {
FILE *f;
if ((f = fopen (filename, "r"))) {
while (fgetpwent_r (f, &pw, buf, sizeof (buf), &pwp) == 0) {
while ((pwp = fgetpwent (f))) {
if (pwp->pw_uid == uid)
break;
}
(void)fclose (f);
}
}
else
getpwuid_r (uid, &pw, buf, sizeof (buf), &pwp);
pwp = getpwuid (uid);

if (pwp == NULL)
errno = ENOENT;
Expand Down

0 comments on commit 6337aa0

Please sign in to comment.