update stuff
This commit is contained in:
parent
5973022688
commit
544ed8b045
194 changed files with 2060 additions and 1464 deletions
65
stdme/src/fs/fd_array_buffer.c
Normal file
65
stdme/src/fs/fd_array_buffer.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fd_array_buffer.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_fd_array *get_fd_arrays(void)
|
||||
{
|
||||
static t_fd_array val = {};
|
||||
|
||||
return (&val);
|
||||
}
|
||||
|
||||
struct s_file_slot *get_unused_fd_slot(void)
|
||||
{
|
||||
t_usize i;
|
||||
t_fd_array *arr;
|
||||
|
||||
arr = get_fd_arrays();
|
||||
i = 0;
|
||||
while (i < FILE_SLOT_LEN)
|
||||
{
|
||||
if (arr->storage[i].ty == SLOT_UNUSED)
|
||||
return (&arr->storage[i]);
|
||||
i++;
|
||||
}
|
||||
me_abort(
|
||||
"Unable to find slot for a file descriptor, increate FILE_SLOT_LEN");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void close_all_fds(void)
|
||||
{
|
||||
t_usize i;
|
||||
t_fd_array *arr;
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/fs/putchar_fd.h"
|
||||
#include "me/fs/write.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
|
||||
void me_putchar_fd(char chr, t_file file)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/fs/putstr_fd.h"
|
||||
#include "me/fs/write.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
|
||||
void me_putendl_fd(t_str str, t_file file)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/fs/putstr_fd.h"
|
||||
#include "me/fs/write.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
|
||||
void me_putstr_fd(t_str str, t_file file)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/fs/open.h"
|
||||
#include "me/fs/read.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
|
||||
#define READ_BUFFER_SIZE 4096
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue