Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Test readdir64 compatibility symbol.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <dirent.h>
20#include <dlfcn.h>
21#include <errno.h>
22#include <shlib-compat.h>
23#include <stdbool.h>
24#include <stdio.h>
25#include <string.h>
26#include <support/check.h>
27
28/* Copied from <olddirent.h>. */
29struct __old_dirent64
30 {
31 __ino_t d_ino;
32 __off64_t d_off;
33 unsigned short int d_reclen;
34 unsigned char d_type;
35 char d_name[256];
36 };
37
38typedef struct __old_dirent64 *(*compat_readdir64_type) (DIR *);
39
40#if TEST_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
41struct __old_dirent64 *compat_readdir64 (DIR *);
42compat_symbol_reference (libc, compat_readdir64, readdir64, GLIBC_2_1);
43#endif
44
45static int
46do_test (void)
47{
48#if TEST_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
49
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);
56
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. */
61 size_t count = 0;
62 while (true)
63 {
64 errno = 0;
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)
70 {
71 if (errno == EOVERFLOW)
72 {
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);
76 break;
77 }
78 if (errno != 0)
79 FAIL_EXIT1 ("compat readdir64 entry %zu: %m\n", count);
80 }
81
82 /* Check that both streams end at the same time. */
83 if (entry_reference == NULL)
84 {
85 TEST_VERIFY (entry_test == NULL);
86 break;
87 }
88 else
89 TEST_VERIFY_EXIT (entry_test != NULL);
90
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);
94
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);
103
104 ++count;
105 }
106 printf ("info: %zu directory entries found\n", count);
107 TEST_VERIFY (count >= 3); /* ".", "..", and some source files. */
108
109 TEST_COMPARE (closedir (dir_test), 0);
110 TEST_COMPARE (closedir (dir_reference), 0);
111#endif
112 return 0;
113}
114
115#include <support/test-driver.c>
116

Warning: That file was not part of the compilation database. It may have many parsing errors.