regtest: broaden none/tests/linux/bug498317 suppression for PPC
[valgrind.git] / none / tests / freebsd / fexecve.c
blobd91f090d04dbbc91b07e36d4f67a09b7d30448ec
1 #include <fcntl.h> // open
2 #include <stdio.h> // perror
3 #include <unistd.h> // getopt
4 #include <stdlib.h> // exit
6 int main(int argc, char **argv, char** envp)
8 char *exe = "./hello_world";
9 int open_flags = 0;
10 int opt;
12 while ((opt = getopt(argc, argv, "erst")) != -1)
14 switch (opt)
16 case 'e':
17 open_flags |= O_EXEC;
18 break;
19 case 'r':
20 open_flags |= O_RDONLY;
21 break;
22 case 's':
23 exe = "./test.sh";
24 break;
25 case 't':
26 exe = "./fexecve.c";
27 break;
28 default:
29 fprintf(stderr, "bad usage, options are\n"
30 "\texec flag\t-e\n"
31 "\trdonly flag\t-r\n"
32 "\texec script\t-s\n"
33 "\ntext file\n-t");
34 exit(-1);
38 int fd = open(exe, open_flags);
39 if (-1 == fd)
41 perror("open failed:");
42 exit(-1);
44 char *new_argv[] = {
45 exe,
46 NULL
48 if (-1 == fexecve(fd, new_argv, envp))
50 perror("fexecv failed:");
51 exit(-1);