en cours de reorganisation des fichiers pour gerer les flags

This commit is contained in:
Hugo LAMY
2019-05-24 18:05:18 +02:00
parent 1a16e305d3
commit 6b9936b0cd
64 changed files with 4351 additions and 51 deletions

38
f_read_file.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/22 15:16:18 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that read and return a ptr to file content
*/
char *read_file(char *file)
{
char buf[BUFF_SIZE];
int fd;
int rv;
int i;
char *result;
if (((fd = open(file, O_RDONLY)) < 0) \
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|| !(result = malloc(sizeof(char) * rv)))
return (NULL);
buf[rv] = '\0';
i = -1;
while (buf[++i])
result[i] = buf[i];
result[i] = '\0';
close(fd);
return (result);
}