diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 22:27:11 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 22:27:11 +0200 |
commit | 62afe606a355581c5b48cca361478c43fb6ae4cf (patch) | |
tree | a278fe2fdf44c296892616554743b9d380ff7afa /libft/src/ft_sprintf.c | |
parent | Added joe-sh_history to gitignore (diff) | |
download | 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.gz 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.bz2 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.xz 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.zst 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.zip |
Well well well that wasn't too bad, now remake everything
Diffstat (limited to 'libft/src/ft_sprintf.c')
-rw-r--r-- | libft/src/ft_sprintf.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libft/src/ft_sprintf.c b/libft/src/ft_sprintf.c new file mode 100644 index 0000000..8413505 --- /dev/null +++ b/libft/src/ft_sprintf.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:07:06 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:07:06 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdarg.h> +#include <unistd.h> + +static int + ft_printf_return(char *str, t_printflist *pflist) +{ + int ret; + + ft_strlcpy(str, pflist->output, pflist->fulllen + 1); + ret = pflist->fulllen; + ft_memdel((void**)&pflist->output); + ft_memdel((void**)&pflist->fullflag); + ft_memdel((void**)&pflist); + return (ret); +} + +int + ft_sprintf(char *str, const char *format, ...) +{ + t_printflist *pflist; + va_list arg; + int pos; + + if (!format) + return (-1); + if ((pos = ft_strlchr(format, '%')) < 0) + return (ft_strlcpy(str, format, ft_strlen(format) + 1)); + else + { + pflist = ft_printf_init_struct(format); + ft_printf_putpart(format, 0, pos, pflist); + va_start(arg, format); + while (pos >= 0) + { + pos = ft_printf_flags(format, pos, arg, pflist); + ft_printf_reinit_struct(pflist); + } + va_end(arg); + return (ft_printf_return(str, pflist)); + } + return (0); +} |