stdme os revamped

This commit is contained in:
Maieul BOYER 2024-08-01 07:26:32 +02:00
parent f29e4ad7ef
commit 2c9a3ee834
No known key found for this signature in database
11 changed files with 285 additions and 274 deletions

37
stdme/src/fs/file_dup.c Normal file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file_dup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/01 06:59:44 by maiboyer #+# #+# */
/* Updated: 2024/08/01 07:03:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/fs/fs.h"
#include "me/str/str.h"
#include "me/types.h"
#include <unistd.h>
t_fd *dup_fd(t_fd *fd)
{
struct s_file_slot *slot;
int tmp;
if (fd == NULL)
return (NULL);
slot = get_unused_fd_slot();
if (slot == NULL)
return (NULL);
tmp = dup(fd->fd);
if (tmp == -1)
return (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);
}