summaryrefslogtreecommitdiff
path: root/source/kit/file.h
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
committerMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
commit2d6c8fec45b23a8a28668ecf3ef281139ab778a7 (patch)
tree75d2a8538992129a83c0c2b83688289443d697e5 /source/kit/file.h
parent820b171245f2f14766f3accdb0246a4e2c0d596a (diff)
downloadsaw-2d6c8fec45b23a8a28668ecf3ef281139ab778a7.zip
refactor dependencies; include dependencies source code
Diffstat (limited to 'source/kit/file.h')
-rw-r--r--source/kit/file.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/source/kit/file.h b/source/kit/file.h
new file mode 100644
index 0000000..b9988f1
--- /dev/null
+++ b/source/kit/file.h
@@ -0,0 +1,142 @@
+#ifndef KIT_FILE_H
+#define KIT_FILE_H
+
+#include "dynamic_array.h"
+#include "status.h"
+#include "string_builder.h"
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# define KIT_PATH_DELIM_C '\\'
+# define KIT_PATH_DELIM "\\"
+# define KIT_ENV_HOME "USERPROFILE"
+#else
+# define KIT_PATH_DELIM_C '/'
+# define KIT_PATH_DELIM "/"
+# define KIT_ENV_HOME "HOME"
+#endif
+
+typedef enum {
+ KIT_PATH_NONE,
+ KIT_PATH_FILE,
+ KIT_PATH_FOLDER
+} kit_path_type_t;
+
+typedef struct {
+ kit_status_t status;
+
+ i64 time_modified_sec;
+ i32 time_modified_nsec;
+ i64 size;
+} kit_file_info_t;
+
+typedef struct {
+ kit_status_t status;
+ KIT_DA(kit_str_builder_t) files;
+} kit_path_list_t;
+
+enum { KIT_FILE_MAP_PRIVATE, KIT_FILE_MAP_SHARED };
+
+typedef struct {
+ kit_status_t status;
+ i64 size;
+ u8 *bytes;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ void *_file;
+ void *_map;
+#else
+ int _fd;
+#endif
+} kit_mapped_file_t;
+
+kit_str_builder_t kit_get_env(kit_str_t name, kit_allocator_t *alloc);
+
+kit_str_builder_t kit_path_norm(kit_str_t path,
+ kit_allocator_t *alloc);
+
+kit_str_builder_t kit_path_join(kit_str_t left, kit_str_t right,
+ kit_allocator_t *alloc);
+
+kit_str_builder_t kit_path_user(kit_allocator_t *alloc);
+
+kit_str_builder_t kit_path_cache(kit_allocator_t *alloc);
+
+kit_str_builder_t kit_path_data(kit_allocator_t *alloc);
+
+kit_str_t kit_path_index(kit_str_t path, i64 index);
+
+kit_str_t kit_path_take(kit_str_t path, i64 count);
+
+kit_status_t kit_folder_create(kit_str_t path);
+
+kit_status_t kit_folder_create_recursive(kit_str_t path);
+
+kit_status_t kit_file_remove(kit_str_t path);
+
+kit_status_t kit_folder_remove(kit_str_t path);
+
+kit_status_t kit_file_remove_recursive(kit_str_t path,
+ kit_allocator_t *alloc);
+
+kit_path_type_t kit_path_type(kit_str_t path);
+
+kit_file_info_t kit_file_info(kit_str_t path);
+
+kit_path_list_t kit_folder_enum(kit_str_t path,
+ kit_allocator_t *alloc);
+
+void kit_path_list_destroy(kit_path_list_t list);
+
+kit_mapped_file_t kit_file_map(kit_str_t path, i64 size, i32 mode);
+kit_status_t kit_file_sync(kit_mapped_file_t *mf);
+kit_status_t kit_file_unmap(kit_mapped_file_t *mf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef KIT_DISABLE_SHORT_NAMES
+# define path_type_t kit_path_type_t
+# define file_info_t kit_file_info_t
+# define path_list_t kit_path_list_t
+# define mapped_file_t kit_mapped_file_t
+
+# define get_env kit_get_env
+# define path_norm kit_path_norm
+# define path_join kit_path_join
+# define path_user kit_path_user
+# define path_cache kit_path_cache
+# define path_data kit_path_data
+# define path_index kit_path_index
+# define path_take kit_path_take
+# define folder_create kit_folder_create
+# define folder_create_recursive kit_folder_create_recursive
+# define file_remove kit_file_remove
+# define folder_remove kit_folder_remove
+# define file_remove_recursive kit_file_remove_recursive
+# define path_type kit_path_type
+# define file_info kit_file_info
+# define folder_enum kit_folder_enum
+# define path_list_destroy kit_path_list_destroy
+# define file_map kit_file_map
+# define file_sync kit_file_sync
+# define file_unmap kit_file_unmap
+
+# define FILE_MAP_PRIVATE KIT_FILE_MAP_PRIVATE
+# define FILE_MAP_SHARED KIT_FILE_MAP_SHARED
+
+# define PATH_DELIM_C KIT_PATH_DELIM_C
+# define PATH_DELIM KIT_PATH_DELIM
+# define ENV_HOME KIT_ENV_HOME
+
+# define PATH_NONE KIT_PATH_NONE
+# define PATH_FILE KIT_PATH_FILE
+# define PATH_FOLDER KIT_PATH_FOLDER
+#endif
+
+#endif