-
Notifications
You must be signed in to change notification settings - Fork 5
/
args_path.c
60 lines (50 loc) · 992 Bytes
/
args_path.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "holberton.h"
/**
*_strcat - concatenate 2 strings
*@dest: is a character
*@src: is a character
*Return: dest concatenated strind
*/
char *_strcat(char *dest, char *src)
{
int i, j;
for (i = 0; dest[i] != '\0'; i++)
{ }
for (j = 0; src[j] != '\0'; j++, i++)
dest[i] = src[j];
dest[i] = '\0';
return (dest);
}
/**
* args_path - concatenates the arguments
* @parse: is a char
* @new: is a char
* Return: total or null
*/
char *args_path(char **parse, char **new)
{
char *total, **cat;
int i, j, k;
struct stat status;
for (i = 0; new[i]; i++)
{
total = malloc(60);
_strcat(total, new[i]);
_strcat(total, "/");
_strcat(total, parse[0]);
if (stat(total, &status) == 0)
{
for (k = 0; parse[k] != '\0'; k++)
;
cat = malloc(sizeof(char *) * (k + 1));
cat[k] = NULL;
cat[0] = _strdup(total);
for (j = 1; parse[j]; j++)
cat[j] = _strdup(parse[j]);
execute(cat);
return (total);
}
free(total);
}
return (NULL);
}