Skip to content
Snippets Groups Projects
Commit 9511f9f2 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

search for binary in pwd

parent 852485d9
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,9 @@
#include <string.h>
#include <err.h>
#include <stdlib.h>
#include <sys/stat.h>
 
#define PROGNAME "adiff.%s"
#define PROGNAME "%s/adiff.%s"
#define VERSION "0.0.1"
 
int main(int argc, char *argv[]) {
......@@ -47,16 +48,26 @@ more:
if (optind == argc || difftype == NULL) {
fprintf(stderr, "Usage: adiff [-V] -t difftype [diff-options] input1 input2");
return EXIT_FAILURE;
} else {
char* program_name = (char*) malloc(sizeof(PROGNAME) - 2 + strlen(difftype) + 1);
sprintf(program_name, PROGNAME, difftype);
if (verbose)
argv[--optind] = (char*) "-V";
}
char* pwd = get_current_dir_name();
int pwdlen = strlen(pwd) + 1;
char* program_name = (char*) malloc(pwdlen + sizeof(PROGNAME) - 3 + strlen(difftype) + 1);
sprintf(program_name, PROGNAME, pwd, difftype);
struct stat buffer;
if(stat (program_name, &buffer) == 1) {
program_name += pwdlen;
pwdlen = 0;
}
if (verbose)
argv[--optind] = (char*) "-V";
 
argv[--optind] = program_name;
argv[--optind] = program_name + pwdlen;
 
execvp(program_name, argv + optind);
perror(program_name);
return EXIT_FAILURE;
}
execvp(program_name, argv + optind);
perror(program_name);
return EXIT_FAILURE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment