READING FILE WORKING

This commit is contained in:
Manzovince
2019-04-14 17:47:13 +02:00
parent f87832a631
commit 451a07b762
4 changed files with 23 additions and 20 deletions

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/14 14:23:24 by vmanzoni ### ########.fr */
/* Updated: 2019/04/14 17:44:18 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,23 +14,24 @@
char *read_file(char *file)
{
char buf[BUFFER_SIZE];
char buf[BUFF_SIZE];
int fd;
int rv;
int i;
char *result;
if (((fd = open(file, O_RDONLY)) < 0) \
|| ((rv = read(fd, &buf, BUFFER_SIZE)) < 0) \
|| !(result = malloc(sizeof(char))))
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|| !(result = malloc(sizeof(char) * rv)))
return (NULL);
buf[rv] = '\0';
i = 0;
while (rv--)
while (buf[i])
{
result[i] = buf[i];
i++;
}
result[i] = '\0';
close(fd);
return (result);
}