42 lines
688 B
C
42 lines
688 B
C
|
#include "minishell"
|
||
|
|
||
|
int ft_file_is_readable(char *path)
|
||
|
{
|
||
|
int readable;
|
||
|
|
||
|
fd = open(path, O_RDONLY);
|
||
|
if (fd == -1)
|
||
|
{
|
||
|
ft_eprintf("minishell: %s: No such file or directory\n", path);
|
||
|
return (0);
|
||
|
}
|
||
|
readable = read(fd, "", 0);
|
||
|
if (readable == -1)
|
||
|
{
|
||
|
ft_eprintf("minishell: %s: Permission denied\n", path);
|
||
|
return (0);
|
||
|
}
|
||
|
close(fd);
|
||
|
return (1);
|
||
|
}
|
||
|
|
||
|
int ft_file_is_writeable(char *path)
|
||
|
{
|
||
|
int writeable;
|
||
|
|
||
|
fd = open(path, O_WRONLY | O_CREAT, 0644);
|
||
|
if (fd == -1)
|
||
|
{
|
||
|
ft_eprintf("bizarre l'erreur");
|
||
|
return (0);
|
||
|
}
|
||
|
writeable = write(fd, "", 0);
|
||
|
if (writeable == -1)
|
||
|
{
|
||
|
ft_eprintf("minishell: %s: Permission denied\n", path);
|
||
|
return (0);
|
||
|
}
|
||
|
close(fd);
|
||
|
return (1);
|
||
|
}
|