minishell
ft_substr.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_substr.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/18 04:37:13 by kfujita #+# #+# */
9 /* Updated: 2022/04/26 00:16:57 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <stddef.h>
14 #include "ft_string.h"
15 
16 char *ft_substr(char const *s, unsigned int start, size_t len)
17 {
18  if (s == NULL)
19  return (NULL);
20  if (len == 0 || ft_strlen(s) <= start)
21  return (ft_strdup(""));
22  return (ft_strndup(s + start, len));
23 }
char * ft_strdup(const char *s1)
Definition: ft_strdup.c:16
char * ft_strndup(const char *s1, size_t n)
Definition: ft_strndup.c:18
size_t ft_strlen(const char *s)
Definition: ft_strlen.c:15
char * ft_substr(char const *s, unsigned int start, size_t len)
Definition: ft_substr.c:16