Skip to content

Instantly share code, notes, and snippets.

@davixcky
Created April 6, 2020 20:37
Show Gist options
  • Save davixcky/2c2afeb7b042cacc57414d775645a61d to your computer and use it in GitHub Desktop.
Save davixcky/2c2afeb7b042cacc57414d775645a61d to your computer and use it in GitHub Desktop.
char *_strcat(char *dest, char *src)
{
int l_dest, i;
l_dest = _strlen(dest);
for (i = 0; src[i] != '\0'; i++, l_dest++)
dest[l_dest] = src[i];
dest[l_dest] = '\0';
return (dest);
}
#include "shell.h"
/**
* _which - Find the directory needed
* @command: Command received
*
* Return: pointer string with found path or NULL in failure.
*/
char *_which(char *command)
{
char **path;
char *split;
char *aux;
char *tmp;
int x = 0;
if (!command)
return (NULL);
tmp = _strdup(command);
command = _strdup("/");
_strcat(command, tmp);
split = _getenv("PATH");
path = split_line(split);
while (path[x] != NULL)
{
split = _strcat(path[x], command);
if (_stat(split) == 0)
return (split);
x++;
}
return (NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment