-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.c
More file actions
78 lines (69 loc) · 1.78 KB
/
buffer.c
File metadata and controls
78 lines (69 loc) · 1.78 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buffer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stoupin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/04/24 13:53:21 by stoupin #+# #+# */
/* Updated: 2017/04/24 14:05:52 by stoupin ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "ft_printf.h"
void buf_print(t_buf *buffer)
{
if (buffer->i > 0)
{
write(1, buffer->data, buffer->i);
}
buffer->i = 0;
}
int buf_putchar(t_buf *buffer, char c)
{
buffer->data[buffer->i++] = c;
if (buffer->i == BUFF_SIZE)
buf_print(buffer);
return (1);
}
int buf_putnchar(t_buf *buffer, char c, int n)
{
int i;
if (n < 0)
return (0);
i = 0;
while (i < n)
{
buffer->data[buffer->i++] = c;
if (buffer->i == BUFF_SIZE)
buf_print(buffer);
i++;
}
return (n);
}
int buf_putstr(t_buf *buffer, const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
buffer->data[buffer->i++] = s[i];
if (buffer->i == BUFF_SIZE)
buf_print(buffer);
i++;
}
return (i);
}
int buf_write(t_buf *buffer, const char *s, int len)
{
int i;
i = 0;
while (i < len)
{
buffer->data[buffer->i++] = s[i];
if (buffer->i == BUFF_SIZE)
buf_print(buffer);
i++;
}
return (len);
}