-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuffer_int.c
More file actions
executable file
·54 lines (47 loc) · 909 Bytes
/
buffer_int.c
File metadata and controls
executable file
·54 lines (47 loc) · 909 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "holberton.h"
/**
* buf_init - Function that create a buffer at a default size of 1024
*
* Return: a pointer to a pointer.
*/
buffer *buf_new()
{
buffer *buf;
buf = malloc(sizeof(buffer));
if (!buf)
return (NULL);
buf->index = 0;
buf->size = 1024;
buf->overflow = 0;
buf->str = malloc(sizeof(char) * buf->size + 1);
return (buf);
}
/**
* buf_custom - Function that create a buffer at a custom
* @size_uint: the desired size of the custom buffer.
*
* Return: a pointer to a buffer
*/
buffer *buf_custom(size_t size_uint)
{
buffer *buf;
buf = malloc(sizeof(buffer));
if (!buf)
return (NULL);
buf->index = 0;
buf->size = size_uint;
buf->overflow = 0;
buf->str = malloc(sizeof(char) * buf->size + 1);
return (buf);
}
/**
* buf_end - frees up the buffer.
* @buf: pointer to a buffer
*/
void buf_end(buffer *buf)
{
if (!buf)
return;
free(buf->str);
free(buf);
}