mirror of git://sourceware.org/git/glibc.git
tst-xdirent: Fix allocating dirent for readdir_r call
As documented in the glibc manual, “Some systems don’t define the d_name element sufficiently long”, and it provides an example of using a union to properly allocate the storage under the dirent.
This commit is contained in:
parent
75fed76dfd
commit
2d196c2e10
|
|
@ -50,10 +50,14 @@ do_test (void)
|
||||||
|
|
||||||
{
|
{
|
||||||
DIR *d = xopendir (".");
|
DIR *d = xopendir (".");
|
||||||
struct dirent buf = { 0, };
|
union
|
||||||
TEST_VERIFY (xreaddir_r (d, &buf));
|
{
|
||||||
TEST_COMPARE_STRING (buf.d_name, ".");
|
struct dirent d;
|
||||||
while (xreaddir_r (d, &buf))
|
char b[offsetof (struct dirent, d_name) + NAME_MAX + 1];
|
||||||
|
} buf;
|
||||||
|
TEST_VERIFY (xreaddir_r (d, &buf.d));
|
||||||
|
TEST_COMPARE_STRING (buf.d.d_name, ".");
|
||||||
|
while (xreaddir_r (d, &buf.d))
|
||||||
;
|
;
|
||||||
xclosedir (d);
|
xclosedir (d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue