Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / posix / tst-execvp2.c
blob440dfab4389b35418b8520e6ce304c1bccb0186c
1 #include <errno.h>
2 #include <libgen.h>
3 #undef basename
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/stat.h>
11 static void prepare (int argc, char *argv[]);
12 static int do_test (void);
13 #define PREPARE(argc, argv) prepare (argc, argv)
14 #define TEST_FUNCTION do_test ()
15 #include "../test-skeleton.c"
17 #ifndef EXECVP
18 # define EXECVP(file, argv) execvp (file, argv)
19 #endif
21 static char *copy;
23 static void
24 prepare (int argc, char *argv[])
26 char *buf;
27 int off;
28 asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
29 if (buf == NULL)
31 puts ("asprintf failed");
32 exit (1);
34 if (system (buf) != 0)
36 puts ("system failed");
37 exit (1);
40 /* Make it not executable. */
41 copy = buf + off;
42 if (chmod (copy, 0666) != 0)
44 puts ("chmod failed");
45 exit (1);
48 add_temp_file (copy);
52 static int
53 do_test (void)
55 /* Make sure we do not find a binary with the name we are going to
56 use. */
57 char *bindir = strdupa (copy);
58 bindir = canonicalize_file_name (dirname (bindir));
59 if (bindir == NULL)
61 puts ("canonicalize_file_name failed");
62 return 1;
64 char *path;
65 asprintf (&path, "%s:../libio:../elf", bindir);
66 if (path == NULL)
68 puts ("asprintf failed");
69 return 1;
72 setenv ("PATH", path, 1);
74 char *argv[] = { basename (copy), NULL };
75 errno = 0;
76 EXECVP (argv[0], argv);
78 if (errno != EACCES)
80 printf ("errno = %d (%m), expected EACCES\n", errno);
81 return 1;
84 return 0;