-
Notifications
You must be signed in to change notification settings - Fork 1
/
sq_main.c
70 lines (62 loc) · 1.86 KB
/
sq_main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sq_main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sloquet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 14:16:54 by sloquet #+# #+# */
/* Updated: 2021/12/08 22:55:34 by sloquet ### ########.fr */
/* */
/* ************************************************************************** */
//#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "get_next_line.h"
#ifndef O_RDONLY
# define O_RDONLY 0
#endif
#ifndef FD_MAX
# define FD_MAX 1024
#endif
#define GNL_CALL 10000
#define THEN_DIFF 1
/*
static void ft_display_stats(void)
{
pthread_attr_t attr;
size_t stacksize;
fprintf(stderr, ">> BUFFER_SIZE %d bytes", BUFFER_SIZE);
fprintf(stderr, " FD_MAX %d", FD_MAX);
fprintf(stderr, " GNL_CALL %d", GNL_CALL);
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &stacksize);
fprintf(stderr, " STACK SIZE %ld bytes\n", stacksize);
pthread_attr_destroy(&attr);
}*/
int main(int ac, char **av)
{
char *line;
int fd;
int i;
(void)ac;
fd = open(av[1], O_RDONLY);
if (!fd)
return (1);
i = 0;
while (i++ < GNL_CALL)
{
line = get_next_line(fd);
if (!line)
break ;
if (THEN_DIFF)
printf("%s", line);
else
printf("line [%02d]: %s", i, line);
free(line);
}
close(fd);
return (0);
}