Cthulhu  0.2.10
Cthulhu compiler collection
os.c File Reference
#include "os/os.h"
#include "os_common.h"
#include "base/util.h"
#include "arena/arena.h"
#include "base/panic.h"
Include dependency graph for os.c:

Go to the source code of this file.

Functions

void os_init (void)
 initialize the os api More...
 
CT_NORETURN os_exit (os_exitcode_t code)
 exit the program More...
 
CT_NORETURN os_thread_exit (os_status_t status)
 exit the current thread of execution More...
 
CT_NORETURN os_abort (void)
 abort the program More...
 
STA_DECL size_t os_error_get_string (os_error_t error, char *buffer, size_t size)
 
STA_DECL char * os_error_string (os_error_t error, arena_t *arena)
 convert an os error code to a string More...
 
STA_DECL char * os_cwd_string (arena_t *arena)
 get the current working directory More...
 
STA_DECL os_error_t os_getcwd (text_t *text, arena_t *arena)
 
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 os_error_t os_unmap (os_mapping_t *mapping)
 
STA_DECL size_t os_mapping_size (const os_mapping_t *mapping)
 get the size of a file mapping More...
 
STA_DECL void * os_mapping_data (os_mapping_t *mapping)
 get the data of a file mapping More...
 
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, not for the validity of the mapping More...
 
STA_DECL os_error_t os_library_open (const char *path, os_library_t *library)
 
STA_DECL os_error_t os_library_close (os_library_t *library)
 
STA_DECL os_error_t os_library_symbol (os_library_t *library, void **symbol, const char *name)
 
STA_DECL const char * os_library_name (const os_library_t *library)
 get the name of a shared library More...
 
STA_DECL os_error_t os_file_open (const char *path, os_access_t access, os_file_t *file)
 
STA_DECL os_error_t os_file_close (os_file_t *file)
 
STA_DECL const char * os_file_name (const os_file_t *file)
 get the name of a file More...
 
STA_DECL os_error_t os_file_create (const char *path)
 create a file More...
 
STA_DECL os_error_t os_file_copy (const char *dst, const char *src)
 copy a file from one location to another More...
 
STA_DECL bool os_dir_exists (const char *path)
 check if a directory exists More...
 
STA_DECL os_error_t os_iter_begin (const char *path, os_iter_t *iter)
 
STA_DECL os_error_t os_iter_end (os_iter_t *iter)
 
STA_DECL bool os_iter_next (os_iter_t *iter, os_inode_t *dir)
 
STA_DECL os_error_t os_iter_error (const os_iter_t *iter)
 get the error state of a directory iterator More...
 
STA_DECL os_dirent_t os_inode_type (const os_inode_t *node)
 get the type of an inode More...
 
STA_DECL const char * os_inode_name (const os_inode_t *node)
 get the name of an inode More...
 
STA_DECL const char * os_thread_name (const os_thread_t *thread)
 
STA_DECL bool os_thread_cmpid (const os_thread_t *thread, os_thread_id_t id)
 

Function Documentation

◆ os_abort()

CT_NORETURN os_abort ( void  )

abort the program

Definition at line 32 of file os.c.

◆ os_cwd_string()

STA_DECL char* os_cwd_string ( arena_t arena)

get the current working directory

Parameters
arenathe arena to allocate from
Returns
an error if the current working directory could not be retrieved

Definition at line 72 of file os.c.

◆ os_dir_exists()

STA_DECL bool os_dir_exists ( const char *  path)

check if a directory exists

fs operations

Definition at line 353 of file os.c.

◆ os_error_get_string()

STA_DECL size_t os_error_get_string ( os_error_t  error,
char *  buffer,
size_t  size 
)

to string operations

Definition at line 43 of file os.c.

◆ os_error_string()

STA_DECL char* os_error_string ( os_error_t  error,
arena_t arena 
)

convert an os error code to a string

Parameters
errorthe error code to convert
arenathe arena to allocate from
Returns
the string representation of the error code

Definition at line 56 of file os.c.

◆ os_exit()

CT_NORETURN os_exit ( os_exitcode_t  code)

exit the program

Parameters
codethe exit code

Definition at line 20 of file os.c.

◆ os_file_close()

STA_DECL os_error_t os_file_close ( os_file_t file)

Definition at line 267 of file os.c.

◆ os_file_create()

STA_DECL os_error_t os_file_create ( const char *  path)

create a file

Parameters
paththe path to the file to create
Returns
an error if the file could not be created

Definition at line 289 of file os.c.

◆ os_file_map()

STA_DECL os_error_t os_file_map ( os_file_t file,
os_protect_t  protect,
size_t  size,
os_mapping_t mapping 
)

mapping operations

Definition at line 113 of file os.c.

◆ os_file_name()

STA_DECL const char* os_file_name ( const os_file_t file)

get the name of a file

Parameters
filethe file to get the name of
Returns
the name of the file

Definition at line 281 of file os.c.

◆ os_file_open()

STA_DECL os_error_t os_file_open ( const char *  path,
os_access_t  access,
os_file_t file 
)

file operations

Definition at line 247 of file os.c.

◆ os_getcwd()

STA_DECL os_error_t os_getcwd ( text_t text,
arena_t arena 
)

Definition at line 88 of file os.c.

◆ os_init()

void os_init ( void  )

initialize the os api

init/exit functions

Definition at line 15 of file os.c.

◆ os_inode_name()

STA_DECL const char* os_inode_name ( const os_inode_t node)

get the name of an inode

Note
the name is only valid for the lifetime of the inode
Parameters
nodethe inode to get the name of
Returns
the name of the inode

Definition at line 457 of file os.c.

◆ os_inode_type()

STA_DECL os_dirent_t os_inode_type ( const os_inode_t node)

get the type of an inode

inode operations

Definition at line 449 of file os.c.

◆ os_iter_begin()

STA_DECL os_error_t os_iter_begin ( const char *  path,
os_iter_t iter 
)

Definition at line 381 of file os.c.

◆ os_iter_end()

STA_DECL os_error_t os_iter_end ( os_iter_t iter)

Definition at line 397 of file os.c.

◆ os_iter_error()

STA_DECL os_error_t os_iter_error ( const os_iter_t iter)

get the error state of a directory iterator

Parameters
iteriterator to check
Returns
the error state of the iterator

Definition at line 437 of file os.c.

◆ os_iter_next()

STA_DECL bool os_iter_next ( os_iter_t iter,
os_inode_t dir 
)

Definition at line 410 of file os.c.

◆ os_library_close()

STA_DECL os_error_t os_library_close ( os_library_t library)

Definition at line 205 of file os.c.

◆ os_library_name()

STA_DECL const char* os_library_name ( const os_library_t library)

get the name of a shared library

Parameters
librarythe library to get the name of
Returns
the name of the library

Definition at line 235 of file os.c.

◆ os_library_open()

STA_DECL os_error_t os_library_open ( const char *  path,
os_library_t library 
)

shared libraries

Definition at line 187 of file os.c.

◆ os_library_symbol()

STA_DECL os_error_t os_library_symbol ( os_library_t library,
void **  symbol,
const char *  name 
)

Definition at line 218 of file os.c.

◆ os_mapping_active()

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, not for the validity of the mapping

Parameters
mappingthe mapping to check
Returns
true if the mapping is valid

Definition at line 175 of file os.c.

◆ os_mapping_data()

STA_DECL void* os_mapping_data ( os_mapping_t mapping)

get the data of a file mapping

Parameters
mappingthe mapping to get the data of
Returns
the data of the mapping

Definition at line 166 of file os.c.

◆ os_mapping_size()

STA_DECL size_t os_mapping_size ( const os_mapping_t mapping)

get the size of a file mapping

Parameters
mappingthe mapping to get the size of
Returns
the size of the mapping

Definition at line 157 of file os.c.

◆ os_thread_cmpid()

STA_DECL bool os_thread_cmpid ( const os_thread_t thread,
os_thread_id_t  id 
)

Definition at line 477 of file os.c.

◆ os_thread_name()

STA_DECL const char* os_thread_name ( const os_thread_t thread)

thread operations

Definition at line 469 of file os.c.

◆ os_unmap()

STA_DECL os_error_t os_unmap ( os_mapping_t mapping)

Definition at line 149 of file os.c.