-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcatenatokens.c
34 lines (33 loc) · 977 Bytes
/
concatenatokens.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
#include "holberton.h"
/**
* concatenatokens - function for concatenates two tokens and add a slash
* This takes two tokens from a strtok operation and merge them to
* execute it with execve in another function.
*
* @tokenscommand: pointer to command token
* @tokenspath: pointer to tokens of the PATH
* @stringconcat: pointer where concatenate string will be save
*
* Return: a pointer to concatenate string
*/
int concatenatokens(char **tokenscommand, char **tokenspath,
char *stringconcat)
{
size_t j = 0, k = 0, l = 0;
struct stat st;
if ((tokenscommand == NULL) || (tokenspath == NULL))
return (-1);
for (j = 0; tokenspath[j] != NULL; j++)
{
for (k = 0; tokenspath[j][k] != '\0'; k++)
stringconcat[k] = tokenspath[j][k];
stringconcat[k] = '/';
k++;
for (l = 0; tokenscommand[0][l] != '\0'; l++, k++)
stringconcat[k] = tokenscommand[0][l];
stringconcat[k] = '\0';
if (stat(stringconcat, &st) == 0)
return (1);
}
return (0);
}