2023-08-19 12:49:23 +00:00
|
|
|
/************************************************************/ /**
|
2023-06-11 16:20:21 +00:00
|
|
|
*
|
|
|
|
* @file: platform_io_internal.h
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 10/06/2023
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
|
|
|
#ifndef __PLATFORM_IO_INTERNAL_H_
|
|
|
|
#define __PLATFORM_IO_INTERNAL_H_
|
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "platform_io.h"
|
2023-08-30 14:45:56 +00:00
|
|
|
#include "platform_io_dialog.h"
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
#if OC_PLATFORM_MACOS || PLATFORM_LINUX
|
2023-08-19 12:49:23 +00:00
|
|
|
typedef int oc_file_desc;
|
2023-08-14 08:26:11 +00:00
|
|
|
#elif OC_PLATFORM_WINDOWS
|
2023-08-19 12:49:23 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
|
|
typedef HANDLE oc_file_desc;
|
2023-06-11 16:20:21 +00:00
|
|
|
#endif
|
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
typedef struct oc_file_slot
|
2023-06-11 16:20:21 +00:00
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
u32 generation;
|
|
|
|
oc_io_error error;
|
|
|
|
bool fatal;
|
|
|
|
oc_list_elt freeListElt;
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
oc_file_type type;
|
|
|
|
oc_file_access rights;
|
|
|
|
oc_file_desc fd;
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
} oc_file_slot;
|
2023-06-11 16:20:21 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
OC_IO_MAX_FILE_SLOTS = 256,
|
2023-06-11 16:20:21 +00:00
|
|
|
};
|
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
typedef struct oc_file_table
|
2023-06-11 16:20:21 +00:00
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
oc_file_slot slots[OC_IO_MAX_FILE_SLOTS];
|
|
|
|
u32 nextSlot;
|
|
|
|
oc_list freeList;
|
2023-08-14 08:26:11 +00:00
|
|
|
} oc_file_table;
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-08-30 14:45:56 +00:00
|
|
|
ORCA_API oc_file_table* oc_file_table_get_global();
|
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_file_slot* oc_file_slot_alloc(oc_file_table* table);
|
|
|
|
void oc_file_slot_recycle(oc_file_table* table, oc_file_slot* slot);
|
|
|
|
oc_file oc_file_from_slot(oc_file_table* table, oc_file_slot* slot);
|
|
|
|
oc_file_slot* oc_file_slot_from_handle(oc_file_table* table, oc_file handle);
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-08-30 14:45:56 +00:00
|
|
|
ORCA_API oc_io_cmp oc_io_wait_single_req_for_table(oc_io_req* req, oc_file_table* table);
|
|
|
|
|
|
|
|
ORCA_API oc_file oc_file_open_with_request_for_table(oc_str8 path, oc_file_access rights, oc_file_open_flags flags, oc_file_table* table);
|
|
|
|
|
|
|
|
ORCA_API oc_file_open_with_dialog_result oc_file_open_with_dialog_for_table(oc_arena* arena,
|
|
|
|
oc_file_access rights,
|
|
|
|
oc_file_open_flags flags,
|
|
|
|
oc_file_dialog_desc* desc,
|
|
|
|
oc_file_table* table);
|
2023-06-11 16:20:21 +00:00
|
|
|
|
2023-06-15 16:27:33 +00:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// raw io primitives
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_file_desc oc_file_desc_nil();
|
|
|
|
bool oc_file_desc_is_nil(oc_file_desc fd);
|
2023-06-15 16:27:33 +00:00
|
|
|
|
|
|
|
/*WARN
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_io_raw_xxx_at functions are similar to posix openat() regarding path resolution,
|
2023-06-15 16:27:33 +00:00
|
|
|
but with some important differences:
|
2023-08-14 08:26:11 +00:00
|
|
|
- If dirFd is a non-nil fd, path is considered relative to dirFd _even if it is an absolute oc_path_
|
2023-06-15 16:27:33 +00:00
|
|
|
- If dirFd is a nil fd, it is _ignored_ (i.e., path can be absolute, or relative to the current directory)
|
|
|
|
|
|
|
|
This means that:
|
|
|
|
- dirFd behaves more like the _root_ of path, ie dirFd won't be ignore if we pass an absolute path,
|
|
|
|
- we don't need a special handle value to use a path relative to the current working directory
|
|
|
|
(we just pass a nil dirFd with a relative path)
|
|
|
|
*/
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_file_desc oc_io_raw_open_at(oc_file_desc dirFd, oc_str8 path, oc_file_access accessRights, oc_file_open_flags openFlags);
|
|
|
|
void oc_io_raw_close(oc_file_desc fd);
|
|
|
|
oc_io_error oc_io_raw_last_error();
|
|
|
|
bool oc_io_raw_file_exists_at(oc_file_desc dirFd, oc_str8 path, oc_file_open_flags openFlags);
|
|
|
|
oc_io_error oc_io_raw_fstat(oc_file_desc fd, oc_file_status* status);
|
|
|
|
oc_io_error oc_io_raw_fstat_at(oc_file_desc dirFd, oc_str8 path, oc_file_open_flags openFlags, oc_file_status* status);
|
|
|
|
|
|
|
|
typedef struct oc_io_raw_read_link_result
|
2023-06-15 16:27:33 +00:00
|
|
|
{
|
2023-08-19 12:49:23 +00:00
|
|
|
oc_io_error error;
|
|
|
|
oc_str8 target;
|
2023-08-14 08:26:11 +00:00
|
|
|
} oc_io_raw_read_link_result;
|
2023-06-15 16:27:33 +00:00
|
|
|
|
2023-08-14 08:26:11 +00:00
|
|
|
oc_io_raw_read_link_result oc_io_raw_read_link_at(oc_arena* arena, oc_file_desc dirFd, oc_str8 path);
|
2023-06-15 16:27:33 +00:00
|
|
|
|
2023-06-11 16:20:21 +00:00
|
|
|
#endif //__PLATFORM_IO_INTERNAL_H_
|