This commit is contained in:
Maix0 2024-05-24 15:28:30 +02:00
parent 6d83a2c196
commit b1cfc0ee71
31 changed files with 133 additions and 89 deletions

View file

@ -14,7 +14,7 @@
#include "me/types.h"
#include <unistd.h>
bool me_close(t_file file, t_i32 *error)
bool me_close(int file, t_i32 *error)
{
t_i32 res;
bool out;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */
/* Updated: 2024/05/19 17:05:40 by maiboyer ### ########.fr */
/* Updated: 2024/05/24 14:44:45 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,7 +40,7 @@ struct s_file_slot *get_unused_fd_slot(void)
return (NULL);
}
void close_all_fds(void)
void close_all_slots(void)
{
t_usize i;
t_fd_array *arr;
@ -48,18 +48,28 @@ void close_all_fds(void)
arr = get_fd_arrays();
i = 0;
while (i < FILE_SLOT_LEN)
{
if (arr->storage[i].ty == SLOT_UNUSED)
;
else if (arr->storage[i].ty == SLOT_FD)
close(arr->storage[i].slot.fd.fd);
else if (arr->storage[i].ty == SLOT_DIR)
closedir(arr->storage[i].slot.dir.ptr);
else if (arr->storage[i].ty == SLOT_FILE)
fclose(arr->storage[i].slot.file.ptr);
else
write(2, "Unknown SLOT type", 17);
mem_set_zero(&arr->storage[i], sizeof(arr->storage[i]));
i++;
}
close_slot(&arr->storage[i++]);
}
void close_slot(struct s_file_slot *slot)
{
if (slot == NULL)
return;
if (slot->ty == SLOT_UNUSED)
;
else if (slot->ty == SLOT_FD)
close(slot->slot.fd.fd);
else if (slot->ty == SLOT_DIR)
closedir(slot->slot.dir.ptr);
else if (slot->ty == SLOT_FILE)
fclose(slot->slot.file.ptr);
else
write(2, "Unknown SLOT type", 17);
mem_set_zero(slot, sizeof(*slot));
}
t_fd *me_open(char *pathname, t_fd_perm permission,
t_file_open_option open_options, t_file_perm fileperm)
{
return (NULL);
}

View file

@ -13,9 +13,9 @@
#include "me/fs/open.h"
#include <fcntl.h>
t_error me_open(t_const_str path, bool read, bool write, t_file *file_out)
t_error me_open(t_const_str path, bool read, bool write, int *file_out)
{
t_file out;
int out;
int flags;
flags = 0;
@ -32,9 +32,9 @@ t_error me_open(t_const_str path, bool read, bool write, t_file *file_out)
return (NO_ERROR);
}
t_error me_open_truncate(t_const_str path, t_file *file_out)
t_error me_open_truncate(t_const_str path, int *file_out)
{
t_file out;
int out;
int flags;
unlink(path);
@ -46,9 +46,9 @@ t_error me_open_truncate(t_const_str path, t_file *file_out)
return (NO_ERROR);
}
t_error me_open_create(t_const_str path, t_file *file_out)
t_error me_open_create(t_const_str path, int *file_out)
{
t_file out;
int out;
int flags;
flags = O_WRONLY | O_CREAT | O_APPEND;

View file

@ -14,7 +14,7 @@
#include "me/fs/write.h"
#include "me/str/str.h"
void me_putchar_fd(char chr, t_file file)
void me_putchar_fd(char chr, int file)
{
me_write(file, (t_u8 *)&chr, 1);
}

View file

@ -14,7 +14,7 @@
#include "me/fs/write.h"
#include "me/str/str.h"
void me_putendl_fd(t_str str, t_file file)
void me_putendl_fd(t_str str, int file)
{
if (str == NULL)
return ;

View file

@ -34,7 +34,7 @@ static void me_inner(t_u64 nb, t_str out, t_usize *idx)
}
}
void me_putnbr_fd(t_i32 n, t_file file)
void me_putnbr_fd(t_i32 n, int file)
{
t_usize idx;
t_i64 nb;

View file

@ -14,7 +14,7 @@
#include "me/fs/write.h"
#include "me/str/str.h"
void me_putstr_fd(t_str str, t_file file)
void me_putstr_fd(t_str str, int file)
{
if (str == NULL)
return ;

View file

@ -13,7 +13,7 @@
#include "me/fs/read.h"
#include <unistd.h>
t_usize me_read(t_file fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out)
t_usize me_read(int fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out)
{
ssize_t out;

View file

@ -21,7 +21,7 @@ bool read_to_vec(t_const_str path, t_vec_u8 *out)
{
t_u8 temp_buffer[READ_BUFFER_SIZE];
t_isize read_amount;
t_file f;
int f;
bool eof;
t_usize current_size;

View file

@ -13,7 +13,7 @@
#include "me/fs/write.h"
#include <unistd.h>
bool me_write(t_file fd, t_u8 *buffer, t_i64 size)
bool me_write(int fd, t_u8 *buffer, t_i64 size)
{
return (write(fd, buffer, size) < 0);
}

View file

@ -20,7 +20,7 @@
#include <stdlib.h>
#include <unistd.h>
static t_static_buffer *get_next_line_buffer(t_file fd)
static t_static_buffer *get_next_line_buffer(int fd)
{
t_usize index;
static t_static_buffer bufs[BUFFER_LENGTH] = {0};
@ -35,7 +35,7 @@ static t_static_buffer *get_next_line_buffer(t_file fd)
return (&bufs[index]);
}
static bool copy_next_line_into_buffer(t_file fd, t_string *out,
static bool copy_next_line_into_buffer(int fd, t_string *out,
char *temp_buffer, t_usize amount)
{
char *buf;
@ -60,7 +60,7 @@ static bool copy_next_line_into_buffer(t_file fd, t_string *out,
return (got_newline);
}
static bool read_and_copy(t_file fd, t_string *out, char *tmp,
static bool read_and_copy(int fd, t_string *out, char *tmp,
t_copy_flags *flags)
{
t_isize amount;
@ -82,7 +82,7 @@ static bool read_and_copy(t_file fd, t_string *out, char *tmp,
return (copy_next_line_into_buffer(fd, out, tmp, (t_usize)amount));
}
static bool handle_leftovers(t_file fd, char *temp_buffer, t_string *buf)
static bool handle_leftovers(int fd, char *temp_buffer, t_string *buf)
{
t_static_buffer *static_buffer;
@ -99,7 +99,7 @@ static bool handle_leftovers(t_file fd, char *temp_buffer, t_string *buf)
return (false);
}
t_string get_next_line(t_file fd, bool *error)
t_string get_next_line(int fd, bool *error)
{
t_string buf;
char *temp_buffer;

View file

@ -21,7 +21,7 @@
t_i32 qoi_write(t_const_str filename, const void *data,
const t_qoi_desc *desc)
{
t_file f;
int f;
void *encoded;
t_i32 size;

View file

@ -14,7 +14,7 @@
t_error create_pipe(t_pipe *out)
{
t_file fds[2];
int fds[2];
if (pipe(fds))
return (ERROR);