/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* open.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */ /* Updated: 2024/07/10 17:43:58 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "me/fs/open.h" #include t_error me_open(t_const_str path, bool read, bool write, int *file_out) { int out; int flags; flags = 0; if (read && write) flags = O_RDWR; else if (read) flags = O_RDONLY; else if (write) flags = O_WRONLY; out = open(path, flags, 0666); if (out < 0) return (ERROR); *file_out = out; return (NO_ERROR); } t_error me_open_truncate(t_const_str path, int *file_out) { int out; int flags; unlink(path); flags = O_WRONLY | O_CREAT | O_TRUNC; out = open(path, flags, 0666); if (out < 0) return (ERROR); *file_out = out; return (NO_ERROR); } t_error me_open_create(t_const_str path, int *file_out) { int out; int flags; flags = O_WRONLY | O_CREAT | O_APPEND; out = open(path, flags, 0666); if (out < 0) return (ERROR); *file_out = out; return (NO_ERROR); }