ft_printf / src / printers / print_s_bonus.c 79 commits
02-05-2026
35 lines 1.4 kB
 1/* ************************************************************************** */
 2/*                                                                            */
 3/*                                                        :::      ::::::::   */
 4/*   print_s_bonus.c                                    :+:      :+:    :+:   */
 5/*                                                    +:+ +:+         +:+     */
 6/*   By: mleitao <mleitao@student.42.fr>            +#+  +:+       +#+        */
 7/*                                                +#+#+#+#+#+   +#+           */
 8/*   Created: 2026/03/31 02:13:27 by mleitao           #+#    #+#             */
 9/*   Updated: 2026/05/02 01:02:39 by mleitao          ###   ########.fr       */
10/*                                                                            */
11/* ************************************************************************** */
12
13#include "printers_bonus.h"
14#include "utils.h"
15
16int	print_s(t_data *d, char *str)
17{
18	int	len;
19
20	if (!str)
21		str = "(null)";
22	len = ft_strlen(str);
23	if (d->format.precision >= 0 && d->format.precision < len)
24		len = d->format.precision;
25	if (!d->format.minus)
26		if (apply_width(d, len) < 0)
27			return (-1);
28	if (putnstr(str, len) < 0)
29		return (-1);
30	d->chars_written += len;
31	if (d->format.minus)
32		if (apply_width(d, len) < 0)
33			return (-1);
34	return (0);
35}