1 /* Test readdir64 compatibility symbol.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <shlib-compat.h>
26 #include <support/check.h>
28 /* Copied from <olddirent.h>. */
33 unsigned short int d_reclen
;
38 typedef struct __old_dirent64
*(*compat_readdir64_type
) (DIR *);
40 #if TEST_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
41 struct __old_dirent64
*compat_readdir64 (DIR *);
42 compat_symbol_reference (libc
, compat_readdir64
, readdir64
, GLIBC_2_1
);
48 #if TEST_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
49 /* Directory stream using the non-compat readdir64 symbol. The test
50 checks against this. */
51 DIR *dir_reference
= opendir (".");
52 TEST_VERIFY_EXIT (dir_reference
!= NULL
);
53 DIR *dir_test
= opendir (".");
54 TEST_VERIFY_EXIT (dir_test
!= NULL
);
56 /* This loop assumes that the enumeration order is consistent for
57 two different handles. Nothing should write to the current
58 directory (in the source tree) while this test runs, so there
59 should not be any difference due to races. */
64 struct dirent64
*entry_reference
= readdir64 (dir_reference
);
65 if (entry_reference
== NULL
&& errno
!= 0)
66 FAIL_EXIT1 ("readdir64 entry %zu: %m\n", count
);
67 struct __old_dirent64
*entry_test
= compat_readdir64 (dir_test
);
68 if (entry_reference
== NULL
)
70 if (errno
== EOVERFLOW
)
72 TEST_VERIFY (entry_reference
->d_ino
73 != (__ino_t
) entry_reference
->d_ino
);
74 printf ("info: inode number overflow at entry %zu\n", count
);
78 FAIL_EXIT1 ("compat readdir64 entry %zu: %m\n", count
);
81 /* Check that both streams end at the same time. */
82 if (entry_reference
== NULL
)
84 TEST_VERIFY (entry_test
== NULL
);
88 TEST_VERIFY_EXIT (entry_test
!= NULL
);
90 /* d_off is never zero because it is the offset of the next
91 entry (not the current entry). */
92 TEST_VERIFY (entry_reference
->d_off
> 0);
94 /* Check that the entries are the same. */
95 TEST_COMPARE_BLOB (entry_reference
->d_name
,
96 strlen (entry_reference
->d_name
),
97 entry_test
->d_name
, strlen (entry_test
->d_name
));
98 TEST_COMPARE (entry_reference
->d_ino
, entry_test
->d_ino
);
99 TEST_COMPARE (entry_reference
->d_off
, entry_test
->d_off
);
100 TEST_COMPARE (entry_reference
->d_type
, entry_test
->d_type
);
101 TEST_COMPARE (entry_reference
->d_reclen
, entry_test
->d_reclen
);
105 printf ("info: %zu directory entries found\n", count
);
106 TEST_VERIFY (count
>= 3); /* ".", "..", and some source files. */
108 TEST_COMPARE (closedir (dir_test
), 0);
109 TEST_COMPARE (closedir (dir_reference
), 0);
114 #include <support/test-driver.c>