]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/tst-readdir64-compat.c
1 /* Test readdir64 compatibility symbol.
2 Copyright (C) 2018 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 <http://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)
50 /* Directory stream using the non-compat readdir64 symbol. The test
51 checks against this. */
52 DIR *dir_reference
= opendir (".");
53 TEST_VERIFY_EXIT (dir_reference
!= NULL
);
54 DIR *dir_test
= opendir (".");
55 TEST_VERIFY_EXIT (dir_test
!= NULL
);
57 /* This loop assumes that the enumeration order is consistent for
58 two different handles. Nothing should write to the current
59 directory (in the source tree) while this test runs, so there
60 should not be any difference due to races. */
65 struct dirent64
*entry_reference
= readdir64 (dir_reference
);
66 if (entry_reference
== NULL
&& errno
!= 0)
67 FAIL_EXIT1 ("readdir64 entry %zu: %m\n", count
);
68 struct __old_dirent64
*entry_test
= compat_readdir64 (dir_test
);
69 if (entry_reference
== NULL
)
71 if (errno
== EOVERFLOW
)
73 TEST_VERIFY (entry_reference
->d_ino
74 != (__ino_t
) entry_reference
->d_ino
);
75 printf ("info: inode number overflow at entry %zu\n", count
);
79 FAIL_EXIT1 ("compat readdir64 entry %zu: %m\n", count
);
82 /* Check that both streams end at the same time. */
83 if (entry_reference
== NULL
)
85 TEST_VERIFY (entry_test
== NULL
);
89 TEST_VERIFY_EXIT (entry_test
!= NULL
);
91 /* d_off is never zero because it is the offset of the next
92 entry (not the current entry). */
93 TEST_VERIFY (entry_reference
->d_off
> 0);
95 /* Check that the entries are the same. */
96 TEST_COMPARE_BLOB (entry_reference
->d_name
,
97 strlen (entry_reference
->d_name
),
98 entry_test
->d_name
, strlen (entry_test
->d_name
));
99 TEST_COMPARE (entry_reference
->d_ino
, entry_test
->d_ino
);
100 TEST_COMPARE (entry_reference
->d_off
, entry_test
->d_off
);
101 TEST_COMPARE (entry_reference
->d_type
, entry_test
->d_type
);
102 TEST_COMPARE (entry_reference
->d_reclen
, entry_test
->d_reclen
);
106 printf ("info: %zu directory entries found\n", count
);
107 TEST_VERIFY (count
>= 3); /* ".", "..", and some source files. */
109 TEST_COMPARE (closedir (dir_test
), 0);
110 TEST_COMPARE (closedir (dir_reference
), 0);
115 #include <support/test-driver.c>