You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
1.2 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fileutils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hroussea <hroussea@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/08 17:52:44 by hroussea #+# #+# */
/* Updated: 2021/06/08 20:08:08 by hroussea ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft/io.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
int open_file(const char *path, int flags, int mode)
{
int fd;
fd = open(path, flags, mode);
if (fd < 0)
perror(path);
else if (read(fd, NULL, 0) < 0)
{
perror(path);
close(fd);
fd = -1;
}
return (fd);
}