mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-20 08:47:19 +08:00

Calls to basename were added here as part of commit e1e1ae6e9b5e "sim: testsuite: fix objdir handling", but that commit missed adding "#include <libgen.h>" or the equivalent GNU extension, see basename(3). Fixing that shows a logical error in the change to openpf1.c; the non-/-prefixed code-path was changed instead of the "/"-prefixed code-path, which is the one executed after that commit. For "newlib" these tests failed linking after that commit. Recent newlib has the (asm-renamed) GNU-extension-variant of basename, but we're better off not using it at all. Unfortunately, compilation failures for C tests run by the machinery in c.exp are currently just marked "unresolved", in contrast to C and assembler tests run by calling run_sim_test. The interaction of calling with the full program-path vs. use of --sysroot exposes a consistency problem: when --sysroot is used, argv[0] isn't the path by which the program can find itself. It's undecided whether argv[0] for the program running in the simulator should be edited (related to the naked argument to the simulator before passing on to the simulated program) to remove a leading --sysroot. Either way, such a change would be out of scope for this commit. * c/stat3.c (mybasename): New macro. Use it instead of basename. * c/openpf1.c: Correct basename-related change and update related comment.
41 lines
994 B
C
41 lines
994 B
C
/* Check that --sysroot is applied to open(2).
|
|
#sim: --sysroot=$pwd
|
|
|
|
We assume, with EXE being the name of the executable:
|
|
- The simulator executes with cwd the same directory where the executable
|
|
is located (also argv[0] contains a plain filename without directory
|
|
components -or- argv[0] contains the full non-sysroot path to EXE).
|
|
- There's no /EXE on the host file system. */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
int main (int argc, char *argv[])
|
|
{
|
|
char *fnam = argv[0];
|
|
FILE *f;
|
|
if (argv[0][0] != '/')
|
|
{
|
|
fnam = malloc (strlen (argv[0]) + 2);
|
|
if (fnam == NULL)
|
|
abort ();
|
|
strcpy (fnam, "/");
|
|
strcat (fnam, argv[0]);
|
|
}
|
|
else
|
|
fnam = strrchr (argv[0], '/');
|
|
|
|
f = fopen (fnam, "rb");
|
|
if (f == NULL)
|
|
abort ();
|
|
fclose (f);
|
|
|
|
/* Cover another execution path. */
|
|
if (fopen ("/nonexistent", "rb") != NULL
|
|
|| errno != ENOENT)
|
|
abort ();
|
|
printf ("pass\n");
|
|
return 0;
|
|
}
|