gcc/
[official-gcc.git] / boehm-gc / if_not_there.c
blob8691e925920eabc542710ca22c9dc9247485cf69
1 /* Conditionally execute a command based if the file argv[1] doesn't exist */
2 /* Except for execvp, we stick to ANSI C. */
3 # include "private/gcconfig.h"
4 # include <stdio.h>
5 # include <stdlib.h>
6 # include <unistd.h>
7 #ifdef __DJGPP__
8 #include <dirent.h>
9 #endif /* __DJGPP__ */
11 int main(argc, argv, envp)
12 int argc;
13 char ** argv;
14 char ** envp;
16 FILE * f;
17 #ifdef __DJGPP__
18 DIR * d;
19 #endif /* __DJGPP__ */
20 if (argc < 3) goto Usage;
21 if ((f = fopen(argv[1], "rb")) != 0
22 || (f = fopen(argv[1], "r")) != 0) {
23 fclose(f);
24 return(0);
26 #ifdef __DJGPP__
27 if ((d = opendir(argv[1])) != 0) {
28 closedir(d);
29 return(0);
31 #endif
32 printf("^^^^Starting command^^^^\n");
33 fflush(stdout);
34 execvp(argv[2], argv+2);
35 exit(1);
37 Usage:
38 fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
39 return(1);