Cthulhu  0.2.10
Cthulhu compiler collection
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
core.h File Reference
#include <ctu_os_api.h>
#include "core/analyze.h"
#include <stddef.h>
#include "os.inc"
Include dependency graph for core.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OS_ACCESS(ID, STR, BIT)   ID = (BIT),
 
#define OS_PROTECT(ID, STR, BIT)   ID = (BIT),
 
#define OS_DIRENT(ID, STR)   ID,
 

Typedefs

typedef struct path_t path_t
 
enum  os_access_t { eOsAccessMask = eOsAccessRead | eOsAccessWrite | eOsAccessTruncate }
 file access mode More...
 
enum  os_protect_t { eOsProtectMask = eOsProtectRead | eOsProtectWrite | eOsProtectExecute }
 file mapping memory protection More...
 
enum  os_dirent_t { eOsNodeCount }
 directory entry type More...
 
typedef typedefCT_BEGIN_API struct os_file_t os_file_t
 file handle More...
 
typedef int os_exitcode_t
 program exit code More...
 
typedef unsigned os_status_t
 thread return code More...
 
typedef size_t os_thread_id_t
 thread id More...
 
typedef void(* os_symbol_t) (void)
 function pointer used for shared library symbols rather than void* because casting a function pointer to void* is undefined behavior More...
 
typedef STA_SUCCESS_TYPE (return==eOsSuccess) size_t os_error_t
 error code More...
 
CT_OS_API void os_init (void)
 initialize the os api More...
 
CT_NORETURN CT_OS_API os_exit (os_exitcode_t code)
 exit the program More...
 
CT_NORETURN CT_OS_API os_thread_exit (os_status_t status)
 exit the current thread of execution More...
 
CT_OS_API os_thread_id_t os_get_thread_id (void)
 get the current thread id More...
 
CT_NORETURN CT_OS_API os_abort (void)
 abort the program More...
 
CT_NODISCARD CT_OS_API size_t os_error_get_string (os_error_t error, STA_WRITES(size) char *buffer, size_t size)
 convert an os error code to a string writes to a buffer rather than allocating. if size is 0, the function will return the number of characters needed to write the string. More...
 
CT_NODISCARD CT_OS_API size_t os_cwd_get_string (STA_WRITES(size) char *buffer, size_t size)
 get the current working directory More...
 
CT_NODISCARD STA_RET_STRING CT_OS_API char * os_error_string (os_error_t error, arena_t *arena)
 convert an os error code to a string More...
 
CT_OS_API char * os_cwd_string (arena_t *arena)
 get the current working directory More...
 
CT_OS_API os_error_t os_getcwd (OUT_NOTNULL text_t *text, arena_t *arena)
 get the current working directory More...
 
CT_NODISCARD CT_PUREFN CT_OS_API os_dirent_t os_inode_type (const os_inode_t *node)
 get the type of an inode More...
 
CT_NODISCARD STA_RET_STRING CT_PUREFN CT_OS_API const char * os_inode_name (const os_inode_t *node)
 get the name of an inode More...
 
CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char * os_dirent_string (os_dirent_t type)
 get the string representation of a directory entry type More...
 
CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char * os_access_string (os_access_t access)
 get the string representation of a file access mode More...
 
CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char * os_protect_string (os_protect_t protect)
 get the string representation of a file mapping memory protection More...
 

Macro Definition Documentation

◆ OS_ACCESS

#define OS_ACCESS (   ID,
  STR,
  BIT 
)    ID = (BIT),

Definition at line 39 of file core.h.

◆ OS_DIRENT

#define OS_DIRENT (   ID,
  STR 
)    ID,

Definition at line 57 of file core.h.

◆ OS_PROTECT

#define OS_PROTECT (   ID,
  STR,
  BIT 
)    ID = (BIT),

Definition at line 48 of file core.h.

Typedef Documentation

◆ os_exitcode_t

typedef int os_exitcode_t

program exit code

Definition at line 67 of file core.h.

◆ os_symbol_t

typedef void(* os_symbol_t) (void)

function pointer used for shared library symbols rather than void* because casting a function pointer to void* is undefined behavior

Definition at line 80 of file core.h.

◆ path_t

typedef struct path_t path_t

Definition at line 1 of file core.h.

Enumeration Type Documentation

◆ os_access_t

file access mode

Enumerator
eOsAccessMask 

Definition at line 37 of file core.h.

◆ os_dirent_t

directory entry type

Enumerator
eOsNodeCount 

Definition at line 55 of file core.h.

◆ os_protect_t

file mapping memory protection

Enumerator
eOsProtectMask 

Definition at line 46 of file core.h.

Function Documentation

◆ os_abort()

CT_NORETURN CT_OS_API os_abort ( void  )

abort the program

Definition at line 32 of file os.c.

◆ os_access_string()

CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char* os_access_string ( os_access_t  access)

get the string representation of a file access mode

Parameters
accessthe file access mode
Returns
the string representation

Definition at line 32 of file os_common.c.

◆ os_cwd_get_string()

CT_NODISCARD CT_OS_API size_t os_cwd_get_string ( STA_WRITES(size) char *  buffer,
size_t  size 
)

get the current working directory

Precondition
buffer must point to a valid buffer of at least size chars
Parameters
bufferthe buffer to write to
sizethe size of the buffer
Returns
the number of characters written, or 0 on error

◆ os_cwd_string()

CT_OS_API 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_dirent_string()

CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char* os_dirent_string ( os_dirent_t  type)

get the string representation of a directory entry type

Parameters
typethe directory entry type
Returns
the string representation

Definition at line 13 of file os_common.c.

◆ os_error_get_string()

CT_NODISCARD CT_OS_API size_t os_error_get_string ( os_error_t  error,
STA_WRITES(size) char *  buffer,
size_t  size 
)

convert an os error code to a string writes to a buffer rather than allocating. if size is 0, the function will return the number of characters needed to write the string.

Precondition
buffer must point to a valid buffer of at least size chars
Parameters
errorthe error code to convert
bufferthe buffer to write to
sizethe size of the buffer
Returns
the number of characters written

◆ os_error_string()

CT_NODISCARD STA_RET_STRING CT_OS_API 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 CT_OS_API os_exit ( os_exitcode_t  code)

exit the program

Parameters
codethe exit code

Definition at line 20 of file os.c.

◆ os_getcwd()

CT_OS_API os_error_t os_getcwd ( OUT_NOTNULL text_t text,
arena_t arena 
)

get the current working directory

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

◆ os_init()

CT_OS_API void os_init ( void  )

initialize the os api

Note
this must be called before using any other os api

init/exit functions

Definition at line 15 of file os.c.

◆ os_inode_name()

CT_NODISCARD STA_RET_STRING CT_PUREFN CT_OS_API 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()

CT_NODISCARD CT_PUREFN CT_OS_API os_dirent_t os_inode_type ( const os_inode_t node)

get the type of an inode

Parameters
nodethe inode to get the type of
Returns
the type of the inode

inode operations

Definition at line 449 of file os.c.

◆ os_protect_string()

CT_NODISCARD CT_CONSTFN STA_RET_STRING CT_OS_API const char* os_protect_string ( os_protect_t  protect)

get the string representation of a file mapping memory protection

Parameters
protectthe file mapping memory protection
Returns
the string representation

Definition at line 50 of file os_common.c.

◆ STA_SUCCESS_TYPE()

typedef STA_SUCCESS_TYPE ( return  = =eOsSuccess)

error code