1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include <sys/stat.h>
7
8#ifndef EXECVP
9# define EXECVP(file, argv) execvp (file, argv)
10#endif
11
12static int
13do_test (void)
14{
15 char buf[40] = "/usr/bin/does-not-exist";
16 size_t stemlen = strlen (buf);
17 struct stat64 st;
18 int cnt = 0;
19 while (stat64 (file: buf, buf: &st) != -1 || errno != ENOENT
20 || stat64 (file: buf + 4, buf: &st) != -1 || errno != ENOENT)
21 {
22 if (cnt++ == 100)
23 {
24 puts (s: "cannot find a unique file name");
25 return 0;
26 }
27
28 strcpy (buf + stemlen, ".XXXXXX");
29 mktemp (template: buf);
30 }
31
32 unsetenv (name: "PATH");
33 char *argv[] = { buf + 9, NULL };
34 EXECVP (argv[0], argv);
35 return 0;
36}
37
38#define TEST_FUNCTION do_test ()
39#include "../test-skeleton.c"
40

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