Skip to content

Commit

Permalink
Default path to .
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoCostaIFG committed Apr 2, 2020
1 parent 7ab35e3 commit c83b19e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/include/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void pathcat(char *path, char *file_name);
/** @brief similar to pathcat but leaves stores result in res */
void pathcpycat(char *res, char *p1, char *p2);

void init(int argc, char **argv, prog_prop *prog_props);
void init(int argc, char ***argv_ret, char **argv, prog_prop *prog_props);

void assemble_args(char **argv, prog_prop *prog_props, char *new_path);

Expand Down
18 changes: 16 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int is_str_num(char *str) {
return 1;
}

void init(int argc, char **argv, prog_prop *prog_props) {
void init(int argc, char ***argv_ret, char **argv, prog_prop *prog_props) {
set_logfile(NULL); // set log file name
get_reftime(); // get/save program's reference starting time
getGrpId(); // set child status
Expand Down Expand Up @@ -163,7 +163,21 @@ void init(int argc, char **argv, prog_prop *prog_props) {
while (optind < argc)
pathcat(prog_props->path, argv[optind++]);
} else {
print_usage();
char **new_argv = (char **)malloc(sizeof(argv) + 1);

int i = 0;
while (argv[i] != NULL) {
new_argv[i] = (char *)malloc(strlen(argv[i]) + 1);
strcpy(new_argv[i], argv[i]);
++i;
}
new_argv[i] = (char *)malloc(sizeof(char) * 2);
strcpy(new_argv[i], ".");
strcpy(prog_props->path, ".");
new_argv[i + 1] = NULL;
*argv_ret = new_argv;

/* print_usage(); */
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/simpledu.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void path_handler(char **argv) {
}

int main(int argc, char *argv[]) {
init(argc, argv, &prog_props);
init(argc, &argv, argv, &prog_props);

/* fd memes */
if (get_upstream_fd(&prog_props.upstream_fd))
Expand Down

0 comments on commit c83b19e

Please sign in to comment.