buffer: add ft_buffer_to_charptr function

This commit is contained in:
Khaïs COLIN 2025-03-10 18:44:37 +01:00
parent cae2dfe4d6
commit 0486368a07
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 36 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/12 12:39:58 by kcolin #+# #+# */
/* Updated: 2025/02/14 18:19:49 by khais ### ########.fr */
/* Updated: 2025/03/10 18:45:34 by khais ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/12 12:35:28 by kcolin #+# #+# */
/* Updated: 2025/02/14 18:20:08 by khais ### ########.fr */
/* Updated: 2025/03/10 18:45:44 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,5 +41,7 @@ t_buffer *ft_buffer_new(void);
void ft_buffer_free(t_buffer *buffer);
t_buffer *ft_buffer_pushchar(t_buffer *buffer, char c);
t_buffer *ft_buffer_push_buf(t_buffer *buffer, char *buf, size_t n);
// buffer_charptr.c
char *ft_buffer_to_charptr(t_buffer *buffer);
#endif

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buffer_charptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/10 18:45:49 by khais #+# #+# */
/* Updated: 2025/03/10 18:46:35 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "buffer.h"
#include <stdlib.h>
/*
** Free this buffer, but return a pointer to the internal string, which is not
** freed.
**
** If buffer is null, return null.
*/
char *ft_buffer_to_charptr(t_buffer *buffer)
{
char *out;
if (buffer == NULL)
return (NULL);
out = buffer->buffer;
free(buffer);
return (out);
}