feature (file_descriptors): added a few more standard file descriptors

This commit is contained in:
antifallobst 2023-04-20 16:47:05 +02:00
parent e3d3faf8e0
commit 18be33952f
2 changed files with 13 additions and 5 deletions

View File

@ -9,10 +9,15 @@
#define FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE 32
typedef int32_t file_descriptor_t;
typedef uint32_t file_descriptor_t;
typedef enum {
FILE_DESCRIPTOR_INVALID = -1
FILE_DESCRIPTOR_INVALID,
FILE_DESCRIPTOR_STDOUT,
FILE_DESCRIPTOR_STDIN,
FILE_DESCRIPTOR_STDERR,
FILE_DESCRIPTORS_ENUM_END
} std_file_descriptors_E;
typedef struct file_descriptor_array_chunk_T file_descriptor_array_chunk_T;

View File

@ -5,7 +5,7 @@
file_descriptor_t file_descriptor_request(file_descriptor_array_T* fd_array, vfs_node_T* node) {
file_descriptor_t fd = 0;
file_descriptor_t fd = FILE_DESCRIPTORS_ENUM_END;
file_descriptor_array_chunk_T* chunk = fd_array->base_chunk;
while (chunk->amount == FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE) {
@ -30,8 +30,9 @@ file_descriptor_t file_descriptor_request(file_descriptor_array_T* fd_array, vfs
}
vfs_node_T* file_descriptor_resolve(file_descriptor_array_T* fd_array, file_descriptor_t fd) {
if (fd == FILE_DESCRIPTOR_INVALID) return NULL;
if (fd < FILE_DESCRIPTORS_ENUM_END) return NULL;
fd -= FILE_DESCRIPTORS_ENUM_END;
uint32_t chunk_selector = fd / FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE;
file_descriptor_array_chunk_T* chunk = fd_array->base_chunk;
@ -49,7 +50,9 @@ vfs_node_T* file_descriptor_resolve(file_descriptor_array_T* fd_array, file_desc
}
void file_descriptor_free(file_descriptor_array_T* fd_array, file_descriptor_t fd) {
if (fd == FILE_DESCRIPTOR_INVALID) return;
if (fd < FILE_DESCRIPTORS_ENUM_END) return;
fd -= FILE_DESCRIPTORS_ENUM_END;
uint32_t chunk_selector = fd / FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE;
file_descriptor_array_chunk_T* chunk = fd_array->base_chunk;