update: normed exec and finish the glob for current directory

This commit is contained in:
maix0 2024-09-18 22:18:31 +02:00
parent cc1e2b7fdc
commit fba538e344
24 changed files with 647 additions and 429 deletions

View file

@ -35,10 +35,10 @@ fs/fs_internal \
fs/getters \
fs/putfd \
gnl/get_next_line \
hash/hasher \
hash/hash_signed \
hash/hash_str \
hash/hash_unsigned \
hash/hasher \
hash/sip/sip13 \
hash/sip/sip_utils \
hash/sip/sip_utils2 \
@ -86,10 +86,6 @@ printf/printf \
printf/printf_fd \
printf/printf_str \
printf/vprintf \
string/mod \
string/string_insert \
string/string_remove \
string/string_reserve \
str/str_clone \
str/str_compare \
str/str_find_chr \
@ -106,6 +102,10 @@ str/str_n_find_str \
str/str_split \
str/str_substring \
str/str_trim \
string/mod \
string/string_insert \
string/string_remove \
string/string_reserve \
GEN_FILES = \
convert/i16_to_str \

View file

@ -1,59 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}