Back to index

lightning-sunbird  0.9+nobinonly
if_not_there.c
Go to the documentation of this file.
00001 /* Conditionally execute a command based if the file argv[1] doesn't exist */
00002 /* Except for execvp, we stick to ANSI C.                         */
00003 # include "gcconfig.h"
00004 # include <stdio.h>
00005 
00006 int main(argc, argv, envp)
00007 int argc;
00008 char ** argv;
00009 char ** envp;
00010 {
00011     FILE * f;
00012     if (argc < 3) goto Usage;
00013     if ((f = fopen(argv[1], "rb")) != 0
00014         || (f = fopen(argv[1], "r")) != 0) {
00015         fclose(f);
00016         return(0);
00017     }
00018     printf("^^^^Starting command^^^^\n");
00019     execvp(argv[2], argv+2);
00020     exit(1);
00021     
00022 Usage:
00023     fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
00024     return(1);
00025 }
00026