mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-23 19:30:10 +00:00
be97091638
Testing for 32-bit x86 shows up a warning "tst-nss-test1.c:25:3: warning: format '%ju' expects argument of type 'uintmax_t', but argument 2 has type 'int' [-Wformat=]". The argument is a difference of two pointers, a signed quantity of type ptrdiff_t for which the right format is %td; this patch makes this test use that format. Tested for 32-bit x86. * nss/tst-nss-test1.c (do_test): Use %td printf format for pointer difference, not %ju.
73 lines
1.5 KiB
C
73 lines
1.5 KiB
C
#include <nss.h>
|
|
#include <pwd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
int retval = 0;
|
|
|
|
__nss_configure_lookup ("passwd", "test1");
|
|
|
|
static const unsigned int pwdids[] = { 100, 30, 200, 60, 20000 };
|
|
#define npwdids (sizeof (pwdids) / sizeof (pwdids[0]))
|
|
setpwent ();
|
|
|
|
const unsigned int *np = pwdids;
|
|
for (struct passwd *p = getpwent (); p != NULL; ++np, p = getpwent ())
|
|
if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
|
|
|| atol (p->pw_name + 4) != *np)
|
|
{
|
|
printf ("passwd entry %td wrong (%s, %u)\n",
|
|
np - pwdids, p->pw_name, p->pw_uid);
|
|
retval = 1;
|
|
break;
|
|
}
|
|
|
|
endpwent ();
|
|
|
|
for (int i = npwdids - 1; i >= 0; --i)
|
|
{
|
|
char buf[30];
|
|
snprintf (buf, sizeof (buf), "name%u", pwdids[i]);
|
|
|
|
struct passwd *p = getpwnam (buf);
|
|
if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
|
|
{
|
|
printf ("passwd entry \"%s\" wrong\n", buf);
|
|
retval = 1;
|
|
}
|
|
|
|
p = getpwuid (pwdids[i]);
|
|
if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
|
|
{
|
|
printf ("passwd entry %u wrong\n", pwdids[i]);
|
|
retval = 1;
|
|
}
|
|
|
|
snprintf (buf, sizeof (buf), "name%u", pwdids[i] + 1);
|
|
|
|
p = getpwnam (buf);
|
|
if (p != NULL)
|
|
{
|
|
printf ("passwd entry \"%s\" wrong\n", buf);
|
|
retval = 1;
|
|
}
|
|
|
|
p = getpwuid (pwdids[i] + 1);
|
|
if (p != NULL)
|
|
{
|
|
printf ("passwd entry %u wrong\n", pwdids[i] + 1);
|
|
retval = 1;
|
|
}
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|