minishell
check_no_opt_str.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* check_no_opt_str.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/24 03:07:49 by kfujita #+# #+# */
9 /* Updated: 2022/04/26 00:21:26 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <limits.h>
14 #include <stddef.h>
15 #include <stdlib.h>
16 #include "ft_printf_local.h"
17 #include "../ft_mem/ft_mem.h"
18 #include "../ft_math/ft_math.h"
19 
20 t_fmt *check_no_opt_str(size_t *len, char **fmt, t_fmt *p_ret)
21 {
22  size_t str_len;
23 
24  str_len = 0;
25  if (p_ret == NULL)
26  p_ret = ft_calloc(1, sizeof(t_fmt));
27  if (p_ret == NULL)
28  return (p_ret);
29  p_ret->type = STR;
30  p_ret->data.str = *fmt;
31  while (*len <= INT_MAX && **fmt != '\0' && **fmt != '%')
32  {
33  str_len++;
34  *len += 1;
35  *fmt += 1;
36  }
37  if (*len > INT_MAX)
38  {
39  free(p_ret);
40  return (NULL);
41  }
42  p_ret->str_len = (int)str_len;
43  *len += ft_max(p_ret->min_len, p_ret->str_len);
44  return (p_ret);
45 }
t_fmt * check_no_opt_str(size_t *len, char **fmt, t_fmt *p_ret)
void * ft_calloc(size_t count, size_t size)
Definition: ft_calloc.c:29
int ft_max(int a, int b)
Definition: ft_max.c:16
@ STR
t_dtype type
t_data data
int str_len
int min_len
char * str