#include "../minishell.h"
char *ft_substr(char *s, int start, size_t len)
{
char *ptr;
unsigned int i;
int end;
i = 0;
end = len + start;
if (!s)
return (NULL);
ptr = (char *)malloc((len + 1) * sizeof(char));
if (!ptr)
exit (1);
if (start <= ft_strlen(s))
{
while (start < end && s[start] != '\0')
{
ptr[i] = s[start];
i++;
start++;
}
}
ptr[i] = '\0';
return (ptr);
}
void free_split(char **arguments)
{
int i;
i = 0;
while (arguments[i])
{
free(arguments[i]);
i++;
}
free(arguments);
}
char *ft_join_args(char *s1, char *s2)
{
char *result;
result = NULL;
result = ft_strjoin(s1, " ");
result = ft_strjoin(result, s2);
return (result);
}
char *ft_strjoin(char *s1, char *s2)
{
int i;
int j;
char *str;
if (!s1)
{
s1 = (char *)malloc(1 * sizeof(char));
if (!s1)
exit (1);
s1[0] = '\0';
}
if (!s2)
return (s1);
str = malloc(ft_strlen(s1) + ft_strlen(s2) + 1);
if (!str)
exit (1);
i = -1;
j = 0;
while (s1 && s1[++i])
str[i] = s1[i];
while (s2[j])
str[i++] = s2[j++];
str[ft_strlen(s1) + ft_strlen(s2)] = '\0';
free(s1);
return (str);
}