OS Abstraction | |
Debug | |
dbg_assert | Breaks into the debugger based on a test. |
dbg_break | Breaks into the debugger. |
dbg_msg | Prints a debug message. |
Memory | |
mem_alloc | Allocates memory. |
mem_free | Frees a block allocated through mem_alloc. |
mem_copy | Copies a a memory block. |
mem_move | Copies a a memory block |
mem_zero | Sets a complete memory block to 0 |
mem_comp | Compares two blocks of memory |
File IO | |
io_open | Opens a file. |
io_read | Reads data into a buffer from a file. |
io_skip | Skips data in a file. |
io_write | Writes data from a buffer to file. |
io_seek | Seeks to a specified offset in the file. |
io_tell | Gets the current position in the file. |
io_length | Gets the total length of the file. |
io_close | Closes a file. |
io_flush | Empties all buffers and writes all pending data. |
io_stdin | Returns an <IOHANDLE> to the standard input. |
io_stdout | Returns an <IOHANDLE> to the standard output. |
io_stderr | Returns an <IOHANDLE> to the standard error. |
Threads | |
thread_sleep | Suspends the current thread for a given period. |
thread_create | Creates a new thread. |
thread_wait | Waits for a thread to be done or destroyed. |
thread_destoy | Destroys a thread. |
thread_yeild | Yeild the current threads execution slice. |
Locks | |
Timer | |
time_get | Fetches a sample from a high resolution timer. |
time_freq | Returns the frequency of the high resolution timer. |
time_timestamp | Retrives the current time as a UNIX timestamp |
Network General | |
net_init | Initiates network functionallity. |
net_host_lookup | Does a hostname lookup by name and fills out the passed NETADDR struct with the recieved details. |
net_addr_comp | Compares two network addresses. |
net_addr_str | Turns a network address into a representive string. |
Network UDP | |
net_udp_create | Creates a UDP socket and binds it to a port. |
net_udp_send | Sends a packet over an UDP socket. |
net_udp_recv | Recives a packet over an UDP socket. |
net_udp_close | Closes an UDP socket. |
Network TCP | |
net_tcp_create | Creates a TCP socket. |
net_tcp_listen | Makes the socket start listening for new connections. |
net_tcp_accept | Polls a listning socket for a new connection. |
net_tcp_connect | Connects one socket to another. |
net_tcp_send | Sends data to a TCP stream. |
net_tcp_recv | Recvives data from a TCP stream. |
net_tcp_close | Closes a TCP socket. |
Strings | |
str_append | Appends a string to another. |
str_copy | Copies a string to another. |
str_format | Performs printf formating into a buffer. |
str_sanitize_strong | Replaces all characters below 32 and above 127 with whitespace. |
str_sanitize | Replaces all characters below 32 and above 127 with whitespace with exception to \r, \n and \r. |
str_comp_nocase | Compares to strings case insensitive. |
str_find_nocase | Finds a string inside another string case insensitive. |
str_hex | Takes a datablock and generates a hexstring of it. |
Filesystem | |
fs_listdir | Lists the files in a directory |
fs_makedir | Creates a directory |
fs_storage_path | Fetches per user configuration directory. |
Undocumented | |
net_tcp_connect_non_blocking | DOCTODO: serp |
net_tcp_set_non_blocking | DOCTODO: serp |
net_tcp_set_non_blocking | DOCTODO: serp |
net_errno | DOCTODO: serp |
net_would_block | DOCTODO: serp |
void *mem_alloc_debug( const char * filename, int line, unsigned size, unsigned alignment )
Allocates memory.
size | Size of the needed block. |
alignment | Alignment for the block. |
Returns a pointer to the newly allocated block. Returns a null pointer if the memory couldn’t be allocated.
int64 time_get()
Fetches a sample from a high resolution timer.
Current value of the timer.
To know how fast the timer is ticking, see time_freq.
int net_udp_send( NETSOCKET sock, const NETADDR * addr, const void * data, int size )
Sends a packet over an UDP socket.
sock | Socket to use. |
addr | Where to send the packet. |
data | Pointer to the packet data to send. |
size | Size of the packet. |
On success it returns the number of bytes sent. Returns -1 on error.
int net_udp_recv( NETSOCKET sock, NETADDR * addr, void * data, int maxsize )
Recives a packet over an UDP socket.
sock | Socket to use. |
addr | Pointer to an NETADDR that will recive the address. |
data | Pointer to a buffer that will recive the data. |
maxsize | Maximum size to recive. |
On success it returns the number of bytes recived. Returns -1 on error.
int net_tcp_accept( NETSOCKET sock, NETSOCKET * new_sock, NETADDR * addr )
Polls a listning socket for a new connection.
sock | Listning socket to poll. |
new_sock | Pointer to a socket to fill in with the new socket. |
addr | Pointer to an address that will be filled in the remote address (optional, can be NULL). |
Returns a non-negative integer on success. Negative integer on failure.
void str_append( char * dst, const char * src, int dst_size )
Appends a string to another.
dst | Pointer to a buffer that contains a string. |
src | String to append. |
dst_size | Size of the buffer of the dst string. |
void str_copy( char * dst, const char * src, int dst_size )
Copies a string to another.
dst | Pointer to a buffer that shall recive the string. |
src | String to be copied. |
dst_size | Size of the buffer dst. |
void str_format( char * buffer, int buffer_size, const char * format, ... )
Performs printf formating into a buffer.
buffer | Pointer to the buffer to recive the formated string. |
buffer_size | Size of the buffer. |
format | printf formating string. |
... | Parameters for the formating. |
int str_comp_nocase( const char * a, const char * b )
Compares to strings case insensitive.
a | String to compare. |
b | String to compare. |
<0 | String a is lesser then string b |
0 | String a is equal to string b |
0 - String a is greater then string b
const char *str_find_nocase( const char * haystack, const char * needle )
Finds a string inside another string case insensitive.
haystack | String to search in |
needle | String to search for |
A pointer into haystack where the needle was found. Returns NULL of needle could not be found.
int fs_storage_path( const char * appname, char * path, int max )
Fetches per user configuration directory.
Returns 0 on success. Negative value on failure.
Breaks into the debugger based on a test.
void dbg_assert( int test, const char * msg )
Breaks into the debugger.
void dbg_break()
Prints a debug message.
void dbg_msg( const char * sys, const char * fmt, ... )
Allocates memory.
void *mem_alloc_debug( const char * filename, int line, unsigned size, unsigned alignment )
Frees a block allocated through mem_alloc.
void mem_free( void * block )
Copies a a memory block.
void mem_copy( void * dest, const void * source, unsigned size )
Copies a a memory block
void mem_move( void * dest, const void * source, unsigned size )
Sets a complete memory block to 0
void mem_zero( void * block, unsigned size )
Compares two blocks of memory
int mem_comp( const void * a, const void * b, int size )
Opens a file.
IOHANDLE io_open( const char * filename, int flags )
Reads data into a buffer from a file.
unsigned io_read( IOHANDLE io, void * buffer, unsigned size )
Skips data in a file.
unsigned io_skip( IOHANDLE io, unsigned size )
Writes data from a buffer to file.
unsigned io_write( IOHANDLE io, const void * buffer, unsigned size )
Seeks to a specified offset in the file.
int io_seek( IOHANDLE io, int offset, int origin )
Gets the current position in the file.
long int io_tell( IOHANDLE io )
Gets the total length of the file.
long int io_length( IOHANDLE io )
Closes a file.
int io_close( IOHANDLE io )
Empties all buffers and writes all pending data.
int io_flush( IOHANDLE io )
Returns an IOHANDLE to the standard input.
IOHANDLE io_stdin()
Returns an IOHANDLE to the standard output.
IOHANDLE io_stdout()
Returns an IOHANDLE to the standard error.
IOHANDLE io_stderr()
Suspends the current thread for a given period.
void thread_sleep( int milliseconds )
Creates a new thread.
void *thread_create( void (*threadfunc)(void *), void * user )
Waits for a thread to be done or destroyed.
void thread_wait( void * thread )
Fetches a sample from a high resolution timer.
int64 time_get()
Returns the frequency of the high resolution timer.
int64 time_freq()
Retrives the current time as a UNIX timestamp
unsigned time_timestamp()
Initiates network functionallity.
int net_init()
Does a hostname lookup by name and fills out the passed NETADDR struct with the recieved details.
int net_host_lookup( const char * hostname, NETADDR * addr, int types )
Compares two network addresses.
int net_addr_comp( const NETADDR * a, const NETADDR * b )
Turns a network address into a representive string.
int net_addr_str( const NETADDR * addr, char * string, int max_length )
Creates a UDP socket and binds it to a port.
NETSOCKET net_udp_create( NETADDR bindaddr )
Sends a packet over an UDP socket.
int net_udp_send( NETSOCKET sock, const NETADDR * addr, const void * data, int size )
Recives a packet over an UDP socket.
int net_udp_recv( NETSOCKET sock, NETADDR * addr, void * data, int maxsize )
Closes an UDP socket.
int net_udp_close( NETSOCKET sock )
Creates a TCP socket.
NETSOCKET net_tcp_create( const NETADDR * a )
Makes the socket start listening for new connections.
int net_tcp_listen( NETSOCKET sock, int backlog )
Polls a listning socket for a new connection.
int net_tcp_accept( NETSOCKET sock, NETSOCKET * new_sock, NETADDR * addr )
Connects one socket to another.
int net_tcp_connect( NETSOCKET sock, const NETADDR * addr )
Sends data to a TCP stream.
int net_tcp_send( NETSOCKET sock, const void * data, int size )
Recvives data from a TCP stream.
int net_tcp_recv( NETSOCKET sock, void * data, int maxsize )
Closes a TCP socket.
int net_tcp_close( NETSOCKET sock )
Appends a string to another.
void str_append( char * dst, const char * src, int dst_size )
Copies a string to another.
void str_copy( char * dst, const char * src, int dst_size )
Performs printf formating into a buffer.
void str_format( char * buffer, int buffer_size, const char * format, ... )
Replaces all characters below 32 and above 127 with whitespace.
void str_sanitize_strong( char * str )
Replaces all characters below 32 and above 127 with whitespace with exception to \r, \n and \r.
void str_sanitize( char * str )
Compares to strings case insensitive.
int str_comp_nocase( const char * a, const char * b )
Finds a string inside another string case insensitive.
const char *str_find_nocase( const char * haystack, const char * needle )
Takes a datablock and generates a hexstring of it.
void str_hex( char * dst, int dst_size, const void * data, int data_size )
Lists the files in a directory
typedef void ( * fs_listdir_callback )(const char *name, int is_dir, void *user)
Creates a directory
int fs_makedir( const char * path )
Fetches per user configuration directory.
int fs_storage_path( const char * appname, char * path, int max )
DOCTODO: serp
int net_tcp_connect_non_blocking( NETSOCKET sock, const NETADDR * a )
DOCTODO: serp
int net_tcp_set_non_blocking( NETSOCKET sock )
DOCTODO: serp
int net_errno()
DOCTODO: serp
int net_would_block()