1 | #include <errno.h> |
2 | #include <stdio.h> |
3 | #include <unistd.h> |
4 | #include <sys/stat.h> |
5 | |
6 | |
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" |
12 | |
13 | |
14 | static char *copy; |
15 | |
16 | static void |
17 | prepare (int argc, char *argv[]) |
18 | { |
19 | char *buf; |
20 | int off; |
21 | |
22 | buf = xasprintf (format: "cp %s %n%s-copy" , argv[0], &off, argv[0]); |
23 | if (system (command: buf) != 0) |
24 | { |
25 | puts (s: "system failed" ); |
26 | exit (1); |
27 | } |
28 | |
29 | /* Make it not executable. */ |
30 | copy = buf + off; |
31 | if (chmod (file: copy, mode: 0666) != 0) |
32 | { |
33 | puts (s: "chmod failed" ); |
34 | exit (1); |
35 | } |
36 | |
37 | add_temp_file (name: copy); |
38 | } |
39 | |
40 | |
41 | static int |
42 | do_test (void) |
43 | { |
44 | errno = 0; |
45 | execl (copy, copy, NULL); |
46 | |
47 | if (errno != EACCES) |
48 | { |
49 | printf (format: "errno = %d (%m), expected EACCES\n" , errno); |
50 | return 1; |
51 | } |
52 | |
53 | return 0; |
54 | } |
55 | |