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

source code of glibc/posix/tst-execle2.c