66 buffer[written] =
'\0';
82 buffer[written] =
'\0';
162 return mapping->
size;
171 return mapping->
view;
190 CTASSERTF(library != NULL,
"invalid library handle used for %s", path);
199 library->
name = path;
239 return library->
name;
251 CTASSERTF(access & (eOsAccessRead | eOsAccessWrite),
"%s: invalid access flags 0x%x", path, access);
252 CTASSERTF(access != (eOsAccessRead | eOsAccessTruncate),
"%s: cannot truncate read only file", path);
294 os_error_t err =
os_file_open(path, eOsAccessWrite | eOsAccessTruncate, &fd);
306 #if CTU_OS_HAS_COPYFILE
319 err =
os_file_open(dst, eOsAccessWrite | eOsAccessTruncate, &dstf);
356 return type == eOsNodeDir;
419 while (iter_next(iter, &data))
432 inode_init(
dir, &data);
481 return thread->
id == id;
int os_exitcode_t
program exit code
CT_NODISCARD CT_OS_API size_t os_cwd_get_string(STA_WRITES(size) char *buffer, size_t size)
get the current working directory
os_dirent_t
directory entry type
os_protect_t
file mapping memory protection
os_access_t
file access mode
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
CT_BASE_API char * ctu_strcpy(STA_WRITES(size) char *dst, const char *src, size_t size)
copy a string equivalent to strcpy but with safety checks
CT_BEGIN_API CT_NODISCARD CT_PUREFN CT_BASE_API bool is_path_special(const char *path)
check if a path is special special paths are paths such as "." and ".." that are not valid for most o...
#define CT_UNREACHABLE()
mark a point in code as unreachable
#define ARENA_MALLOC(size, name, parent, arena)
allocate memory from a custom allocator
STA_DECL os_error_t os_file_copy(const char *dst, const char *src)
copy a file from one location to another
CT_NORETURN os_thread_exit(os_status_t status)
exit the current thread of execution
unsigned os_status_t
thread return code
size_t os_thread_id_t
thread id
#define CTASSERT(expr)
assert a condition, prints the condition as a message
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
STA_DECL const char * os_thread_name(const os_thread_t *thread)
STA_DECL os_error_t os_file_create(const char *path)
create a file
STA_DECL os_error_t os_unmap(os_mapping_t *mapping)
CT_NORETURN os_exit(os_exitcode_t code)
exit the program
STA_DECL void * os_mapping_data(os_mapping_t *mapping)
get the data of a file mapping
STA_DECL os_dirent_t os_inode_type(const os_inode_t *node)
get the type of an inode
STA_DECL os_error_t os_iter_end(os_iter_t *iter)
STA_DECL os_error_t os_library_symbol(os_library_t *library, void **symbol, const char *name)
STA_DECL os_error_t os_file_map(os_file_t *file, os_protect_t protect, size_t size, os_mapping_t *mapping)
STA_DECL size_t os_error_get_string(os_error_t error, char *buffer, size_t size)
void os_init(void)
initialize the os api
STA_DECL os_error_t os_library_open(const char *path, os_library_t *library)
STA_DECL bool os_thread_cmpid(const os_thread_t *thread, os_thread_id_t id)
STA_DECL bool os_dir_exists(const char *path)
check if a directory exists
STA_DECL const char * os_inode_name(const os_inode_t *node)
get the name of an inode
STA_DECL os_error_t os_file_open(const char *path, os_access_t access, os_file_t *file)
STA_DECL bool os_mapping_active(const os_mapping_t *mapping)
does the mapping object contain a valid mapping checks if the mapping data exists,...
CT_NORETURN os_abort(void)
abort the program
STA_DECL char * os_error_string(os_error_t error, arena_t *arena)
convert an os error code to a string
STA_DECL bool os_iter_next(os_iter_t *iter, os_inode_t *dir)
STA_DECL size_t os_mapping_size(const os_mapping_t *mapping)
get the size of a file mapping
STA_DECL os_error_t os_getcwd(text_t *text, arena_t *arena)
STA_DECL os_error_t os_file_close(os_file_t *file)
STA_DECL os_error_t os_library_close(os_library_t *library)
STA_DECL os_error_t os_iter_error(const os_iter_t *iter)
get the error state of a directory iterator
STA_DECL const char * os_file_name(const os_file_t *file)
get the name of a file
STA_DECL const char * os_library_name(const os_library_t *library)
get the name of a shared library
STA_DECL os_error_t os_iter_begin(const char *path, os_iter_t *iter)
STA_DECL char * os_cwd_string(arena_t *arena)
get the current working directory
CT_NODISCARD CT_OS_API os_dirent_t os_dirent_type(const char *path)
get the type of a paths inode entry
CT_OS_API os_error_t os_file_size(os_file_t *file, OUT_NOTNULL size_t *actual)
get the size of a file
CT_OS_API os_error_t os_file_read(os_file_t *file, STA_WRITES(size) void *buffer, size_t size, OUT_NOTNULL size_t *actual)
read from a file
CT_OS_API os_error_t os_file_write(os_file_t *file, STA_READS(size) const void *buffer, size_t size, OUT_NOTNULL size_t *actual)
write to a file
CT_NODISCARD OUT_NOTNULL os_inode_t * dir
CT_LOCAL os_library_impl_t impl_library_open(const char *path)
STA_LAST_ERROR CT_LOCAL os_error_t impl_last_error(void)
CT_LOCAL os_dirent_t impl_inode_type(const os_inode_impl_t *inode)
CT_LOCAL bool impl_iter_close(os_iter_impl_t impl)
CT_LOCAL os_error_t impl_unmap(os_mapping_t *map)
CT_LOCAL size_t impl_error_length(os_error_t error)
CT_BEGIN_API CT_LOCAL void impl_init(void)
CT_LOCAL bool impl_library_close(os_library_impl_t lib)
CT_LOCAL bool impl_iter_next(os_iter_impl_t impl, os_inode_impl_t *inode)
CT_LOCAL bool impl_file_close(os_file_impl_t impl)
CT_LOCAL void impl_thread_exit(os_status_t status)
CT_LOCAL void * impl_file_map(os_file_t *file, os_protect_t protect, size_t size, os_mapping_t *map)
CT_LOCAL void impl_abort(void)
CT_LOCAL void * impl_library_symbol(os_library_impl_t lib, const char *name)
CT_LOCAL void impl_exit(os_exitcode_t code)
CT_LOCAL os_iter_impl_t impl_iter_open(const char *path, os_inode_impl_t *inode)
CT_LOCAL os_error_t impl_copyfile(const char *dst, const char *src)
CT_LOCAL const char * impl_inode_name(const os_inode_impl_t *inode)
CT_LOCAL os_file_impl_t impl_file_open(const char *path, os_access_t access)
CT_LOCAL size_t impl_error_string(os_error_t error, char *buffer, size_t size)
#define CT_OS_INVALID_LIBRARY
#define CT_OS_INVALID_MAPPING
#define CT_OS_INVALID_ITER
struct dirent * os_inode_impl_t
#define CT_OS_INVALID_FILE
char name[CT_OS_NAME_MAX]
size_t length
the number of characters in the text