debug: Improve mqueue.h fortify warnings with clang
[glibc.git] / posix / tst-execve2.c
blobe0a7c843463c38ade188f72cba92d9c7c585f138
1 #include <errno.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/stat.h>
7 static void prepare (int argc, char *argv[]);
8 static int do_test (void);
9 #define PREPARE(argc, argv) prepare (argc, argv)
10 #define TEST_FUNCTION do_test ()
11 #include "../test-skeleton.c"
14 static char *copy;
16 static void
17 prepare (int argc, char *argv[])
19 char *buf;
20 int off;
22 buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]);
23 if (system (buf) != 0)
25 puts ("system failed");
26 exit (1);
29 /* Make it not executable. */
30 copy = buf + off;
31 if (chmod (copy, 0666) != 0)
33 puts ("chmod failed");
34 exit (1);
37 add_temp_file (copy);
41 static int
42 do_test (void)
44 char *argv[] = { copy, NULL };
45 char *envp[] = { (char *) "FOO=BAR", NULL };
47 errno = 0;
48 execve (copy, argv, envp);
50 if (errno != EACCES)
52 printf ("errno = %d (%m), expected EACCES\n", errno);
53 return 1;
56 return 0;