aboutsummaryrefslogtreecommitdiff
path: root/ft_printf/convert_str.c
blob: 7d51a5ecd67205b2a080559aa265004d919ff140 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   convert_str.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/10/30 23:22:25 by cacharle          #+#    #+#             */
/*   Updated: 2019/11/09 01:07:24 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ft_vasprintf.h"

char	*convert_str(va_list ap, t_pformat *pformat)
{
	char *str;

	str = va_arg(ap, char*);
	str = str == NULL ? ft_strdup("(null)") : ft_strdup(str);
	if (pformat->precision >= 0 && pformat->precision < (int)ft_strlen(str))
		str[pformat->precision] = '\0';
	str = handle_width(pformat, str);
	return (str);
}