1 /* Copyright (C) 2013-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <elf.h>
19 #include <errno.h>
20 #include <link.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <misc/sys/auxv.h>
25
26 static int
do_test(int argc,char * argv[])27 do_test (int argc, char *argv[])
28 {
29 errno = 0;
30 const char *execfn = (const char *) getauxval (AT_NULL);
31
32 if (errno != ENOENT)
33 {
34 printf ("errno is %d rather than %d (ENOENT) on failure\n", errno,
35 ENOENT);
36 return 1;
37 }
38
39 if (execfn != NULL)
40 {
41 printf ("getauxval return value is nonzero on failure\n");
42 return 1;
43 }
44
45 errno = 0;
46 execfn = (const char *) getauxval (AT_EXECFN);
47
48 if (execfn == NULL)
49 {
50 printf ("No AT_EXECFN found, AT_EXECFN test skipped\n");
51 return 0;
52 }
53
54 if (errno != 0)
55 {
56 printf ("errno erroneously set to %d on success\n", errno);
57 return 1;
58 }
59
60 if (strcmp (argv[0], execfn) != 0)
61 {
62 printf ("Mismatch: argv[0]: %s vs. AT_EXECFN: %s\n", argv[0], execfn);
63 return 1;
64 }
65
66 return 0;
67 }
68
69 #define TEST_FUNCTION_ARGV do_test
70 #include <support/test-driver.c>
71