-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.c
52 lines (49 loc) · 1.53 KB
/
test1.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalcabre <dalcabre@student.42urduliz.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/28 13:36:55 by dalcabre #+# #+# */
/* Updated: 2024/03/01 10:55:58 by dalcabre ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int main(int argc, char *argv[])
{
int fd;
char *buffer;
int size = 0;
buffer = (char *)malloc(MAX_BUFFER_SIZE);
if (!buffer)
{
write(2, "Memory assigment error", 23);
return (1);
}
fd = open ("el_x_venir.txt", O_RDONLY);
if (fd == -1)
{
write(2, "Cannot open file", 17);
free (buffer);
return (1);
}
size = read(fd, buffer, MAX_BUFFER_SIZE);
if (size == -1)
{
write(2, "Cannot read file", 17);
free (buffer);
close (fd);
return (1);
}
if (write(1, buffer, size) == -1)
{
write(2, "Cannot write in standart output", 31);
free (buffer);
close (fd);
return (1);
}
free (buffer);
close (fd);
return (0);
}