update: fixed heredoc finaly :D
This commit is contained in:
parent
da223422b0
commit
cc1e2b7fdc
7 changed files with 77 additions and 13 deletions
59
stdme/src/fs/file_dup_bak.c
Normal file
59
stdme/src/fs/file_dup_bak.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* file_dup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/01 06:59:44 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/18 14:24:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
#include <unistd.h>
|
||||
|
||||
static int _get_flags(t_fd *fd)
|
||||
{
|
||||
int out;
|
||||
out = 0;
|
||||
if (fd->perms & FD_READ && fd->perms & FD_WRITE)
|
||||
out = O_RDWR;
|
||||
else if (fd->perms & FD_READ)
|
||||
out = O_RDONLY;
|
||||
else if (fd->perms & FD_WRITE)
|
||||
out = O_WRONLY;
|
||||
|
||||
return (out);
|
||||
}
|
||||
|
||||
t_fd *dup_fd(t_fd *fd)
|
||||
{
|
||||
struct s_file_slot *slot;
|
||||
int tmp;
|
||||
t_string path;
|
||||
|
||||
if (fd == NULL)
|
||||
return (NULL);
|
||||
slot = get_unused_fd_slot();
|
||||
if (slot == NULL)
|
||||
return (NULL);
|
||||
path = string_new(32);
|
||||
me_printf_str(&path, "/proc/self/fd/%i", fd->fd);
|
||||
tmp = open(path.buf, O_CLOEXEC | _get_flags(fd));
|
||||
string_free(path);
|
||||
if (tmp == -1)
|
||||
return (printf("There was an error while duping the "\
|
||||
"fd %d `%s`\n", fd->fd, fd->name), NULL);
|
||||
slot->ty = SLOT_FD;
|
||||
slot->slot.fd.fd = tmp;
|
||||
slot->slot.fd.perms = fd->perms;
|
||||
slot->slot.fd.type = fd->type;
|
||||
slot->slot.fd.name = str_clone(fd->name);
|
||||
return (&slot->slot.fd);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/04 17:59:48 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/14 17:51:38 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/18 14:24:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/11 12:00:25 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/17 17:12:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ t_error spawn_process(t_spawn_info info, t_process *process)
|
|||
(spawn_process_exec(info, process), exit(1));
|
||||
else
|
||||
{
|
||||
_process_cleanup(info, process, false);
|
||||
_process_cleanup(info, process, process->pid == -1);
|
||||
if (process->pid == -1)
|
||||
return (ERROR);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue