#ifndef TINY_CONVMEM_SYS_SYSTEM_H #define TINY_CONVMEM_SYS_SYSTEM_H #include #include #include typedef enum tiny_sys_status { TINY_SYS_OK = 0, TINY_SYS_NOT_FOUND, TINY_SYS_BUSY, TINY_SYS_ERROR } tiny_sys_status_t; typedef enum tiny_sys_file_mode { TINY_SYS_FILE_READ = 0, TINY_SYS_FILE_WRITE_NEW, TINY_SYS_FILE_READ_WRITE, TINY_SYS_FILE_READ_WRITE_CREATE, TINY_SYS_FILE_LOCK } tiny_sys_file_mode_t; typedef enum tiny_sys_seek_origin { TINY_SYS_SEEK_BEGIN = 0, TINY_SYS_SEEK_CURRENT, TINY_SYS_SEEK_END } tiny_sys_seek_origin_t; typedef struct tiny_sys_file { intptr_t native; } tiny_sys_file_t; typedef struct tiny_sys_arguments { int count; char **values; } tiny_sys_arguments_t; /* Internal test seam. A call index of 1 fails the next matching operation. */ typedef enum tiny_sys_test_operation { TINY_SYS_TEST_OPEN = 0, TINY_SYS_TEST_READ, TINY_SYS_TEST_WRITE, TINY_SYS_TEST_SEEK, TINY_SYS_TEST_SIZE, TINY_SYS_TEST_TRUNCATE, TINY_SYS_TEST_FLUSH, TINY_SYS_TEST_REPLACE, TINY_SYS_TEST_RANDOM, TINY_SYS_TEST_OPERATION_COUNT } tiny_sys_test_operation_t; void tiny_sys_test_reset(void); bool tiny_sys_test_fail_after(tiny_sys_test_operation_t operation, size_t call_index); void tiny_sys_test_max_transfer(uint32_t length); bool tiny_sys_arguments_init(tiny_sys_arguments_t *arguments, int argc, char **argv); void tiny_sys_arguments_free(tiny_sys_arguments_t *arguments); char *tiny_sys_path_absolute(const char *path); char *tiny_sys_path_join(const char *directory, const char *name); char *tiny_sys_temp_directory_create(const char *prefix); tiny_sys_status_t tiny_sys_directory_create(const char *path); bool tiny_sys_file_remove(const char *path); bool tiny_sys_directory_remove(const char *path); bool tiny_sys_path_replace(const char *source, const char *destination); void tiny_sys_file_init(tiny_sys_file_t *file); bool tiny_sys_file_valid(const tiny_sys_file_t *file); tiny_sys_status_t tiny_sys_file_open(tiny_sys_file_t *file, const char *path, tiny_sys_file_mode_t mode); void tiny_sys_file_close(tiny_sys_file_t *file); bool tiny_sys_file_read(tiny_sys_file_t *file, void *data, uint32_t length, uint32_t *actual); bool tiny_sys_file_write(tiny_sys_file_t *file, const void *data, uint32_t length, uint32_t *actual); bool tiny_sys_file_seek(tiny_sys_file_t *file, int64_t offset, tiny_sys_seek_origin_t origin); bool tiny_sys_file_size(const tiny_sys_file_t *file, uint64_t *size); bool tiny_sys_file_truncate(tiny_sys_file_t *file); bool tiny_sys_file_flush(tiny_sys_file_t *file); uint64_t tiny_sys_now_milliseconds(void); uint64_t tiny_sys_monotonic_milliseconds(void); bool tiny_sys_random_bytes(void *data, size_t length); #endif