(feat): cherche l'executable en entrée dans la variable env PATH
This commit is contained in:
parent
03140543ce
commit
dc32c7d993
@ -6,6 +6,7 @@
|
|||||||
#include "../cmd/cmd.h"
|
#include "../cmd/cmd.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "../env/env.h"
|
#include "../env/env.h"
|
||||||
|
#include "../utils/utils.h"
|
||||||
#include "../../lib/bozolib/bozolib.h"
|
#include "../../lib/bozolib/bozolib.h"
|
||||||
|
|
||||||
int len(void** list)
|
int len(void** list)
|
||||||
@ -101,16 +102,23 @@ char* get_executable_path(char* executable, lst** env)
|
|||||||
int size_path_str;
|
int size_path_str;
|
||||||
char * path_file;
|
char * path_file;
|
||||||
char* path_env = get_env_variable(env, "PATH");
|
char* path_env = get_env_variable(env, "PATH");
|
||||||
char** path_env_splited =split(path_env, ":");
|
char** path_env_splited =split_quoted_charset(path_env, ":");
|
||||||
|
|
||||||
for (int i=0; path_env_splited[i] != NULL; i++)
|
for (int i=0; path_env_splited[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
size_path_str = strlen(path_env_splited[i])+strlen(executable);
|
size_path_str = strlen(path_env_splited[i])+strlen(executable);
|
||||||
path_file = malloc(size_path_str*sizeof(char*));
|
path_file = malloc((size_path_str+1)*sizeof(char*));
|
||||||
strcpy(path_file, path_env_splited[i]);
|
strcpy(path_file, path_env_splited[i]);
|
||||||
|
strcat(path_file, "/");
|
||||||
strcat(path_file, executable);
|
strcat(path_file, executable);
|
||||||
if (access(path_file, X_OK) == 0)
|
if (access(path_file, X_OK) == 0)
|
||||||
|
{
|
||||||
|
tab_free((void**)path_env_splited);
|
||||||
return path_file;
|
return path_file;
|
||||||
|
}
|
||||||
|
|
||||||
free(path_file);
|
free(path_file);
|
||||||
}
|
}
|
||||||
|
tab_free((void**)path_env_splited);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int command_list_exec(cmd** cmds, lst** env)
|
int command_list_exec(cmd** cmds, lst** env);
|
||||||
int execute(cmd* input, lst** env);
|
int execute(cmd* input, lst** env);
|
||||||
int builtin_execute(cmd* input, lst** env);
|
int builtin_execute(cmd* input, lst** env);
|
||||||
int piper(cmd** cmds, lst** env);
|
int piper(cmd** cmds, lst** env);
|
||||||
|
Loading…
Reference in New Issue
Block a user