(fix): warnings in exec.c + bin executable
This commit is contained in:
parent
7a62ed848f
commit
fb6e338224
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
int execute(cmd** input, char** env)
|
int execute(cmd** input, char** env)
|
||||||
{
|
{
|
||||||
|
int exitcode;
|
||||||
for(int i=0; input[i]!=NULL; i++)
|
for(int i=0; input[i]!=NULL; i++)
|
||||||
{
|
{
|
||||||
// création d'un processus enfant du programme
|
// création d'un processus enfant du programme
|
||||||
@ -18,20 +19,17 @@ int execute(cmd** input, char** env)
|
|||||||
// redirige la sortie standard vers un file descriptor
|
// redirige la sortie standard vers un file descriptor
|
||||||
dup2(1, input[i]->fd_out);
|
dup2(1, input[i]->fd_out);
|
||||||
// on tue l'enfant (l'enfant devient la commande entrée par l'utilisateur)
|
// on tue l'enfant (l'enfant devient la commande entrée par l'utilisateur)
|
||||||
execve(input[i]->executable, input[i]->args, env);
|
exitcode = execve(input[i]->executable, input[i]->args, env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int builtin_execute(cmd** input, char** env)
|
int len(char** list)
|
||||||
{
|
{
|
||||||
for(int i=0; input[i]!=NULL; i++)
|
int index;
|
||||||
{
|
for (index = 0; list[index]!=NULL; index++);
|
||||||
if (strcmp(input[i]->executable, "cd") == 0)
|
return index;
|
||||||
{
|
|
||||||
change_directory(input[i]->args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int change_directory(char** args)
|
int change_directory(char** args)
|
||||||
@ -49,16 +47,24 @@ int change_directory(char** args)
|
|||||||
char cwd[PATH_MAX];
|
char cwd[PATH_MAX];
|
||||||
if (getcwd(cwd, sizeof(cwd)) != NULL)
|
if (getcwd(cwd, sizeof(cwd)) != NULL)
|
||||||
{
|
{
|
||||||
printf("Current working dir: %s\n", cwd);
|
printf("cd %s \nCurrent working dir: %s\n", args[1], cwd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len(char** list)
|
int builtin_execute(cmd** input, char** env)
|
||||||
{
|
{
|
||||||
int index;
|
int exitcode;
|
||||||
for (index = 0; list[index]!=NULL; index++);
|
(void) env;
|
||||||
return index;
|
for(int i=0; input[i]!=NULL; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(input[i]->executable, "cd") == 0)
|
||||||
|
{
|
||||||
|
exitcode = change_directory(input[i]->args);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
Loading…
Reference in New Issue
Block a user