-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalloca_start_end.c
30 lines (27 loc) · 1.18 KB
/
alloca_start_end.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* alloca_start_end.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emohamed <emohamed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/29 10:59:27 by emohamed #+# #+# */
/* Updated: 2023/09/30 05:13:12 by emohamed ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *alloc_s(char const *s, int start, int len)
{
char *stock;
if (!s || !s[0])
return (NULL);
if (start >= ft_strlen(s))
return ("");
if (len > ft_strlen(s))
len = ft_strlen(s);
stock = ft_strdup(s + start);
if (!stock)
return (NULL);
stock[len] = '\0';
return (stock);
}