1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/* Verify that fopen works with copy relocation on _IO_stderr_ in binaries
linked with glibc 2.0.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <shlib-compat.h>
#if TEST_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
# define _LIBC
# define _IO_USE_OLD_IO_FILE
# include <stdio.h>
# include <string.h>
# include <unistd.h>
# include <limits.h>
# include <sys/stat.h>
# include <support/check.h>
struct _IO_jump_t;
struct _IO_FILE_plus
{
FILE file;
const struct _IO_jump_t *vtable;
};
extern struct _IO_FILE_plus _IO_stderr_;
compat_symbol_reference (libc, _IO_stderr_, _IO_stderr_, GLIBC_2_0);
compat_symbol_reference (libc, fopen, fopen, GLIBC_2_0);
compat_symbol_reference (libc, fclose, fclose, GLIBC_2_0);
static int
do_test (int argc, char *argv[])
{
static char filename[PATH_MAX + 1];
struct stat st;
char *name = NULL;
int i;
/* Try to trigger copy relocation. */
TEST_VERIFY_EXIT (_IO_stderr_.file._fileno == STDERR_FILENO);
for (i = 1; i < argc; i++)
{
name = argv[i];
if (stat (name, &st) == 0)
{
TEST_VERIFY_EXIT (strlen (name) <= PATH_MAX);
break;
}
}
TEST_VERIFY_EXIT (name != NULL);
strcpy (filename, name);
FILE *fp = fopen (filename, "r");
TEST_VERIFY_EXIT (strcmp (filename, name) == 0);
TEST_VERIFY_EXIT (fp != NULL);
TEST_VERIFY_EXIT (fclose (fp) == 0);
return 0;
}
#else
# include <support/test-driver.h>
static int
do_test (int argc, char *argv[])
{
return EXIT_UNSUPPORTED;
}
#endif
#define TEST_FUNCTION_ARGV do_test
#include <support/test-driver.c>
|