2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Title: OS Abstraction
|
|
|
|
*/
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
#ifndef BASE_SYSTEM_H
|
|
|
|
#define BASE_SYSTEM_H
|
|
|
|
|
2008-08-14 17:19:13 +00:00
|
|
|
#include "detect.h"
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Group: Debug */
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: dbg_assert
|
2008-07-06 11:21:21 +00:00
|
|
|
Breaks into the debugger based on a test.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
test - Result of the test.
|
|
|
|
msg - Message that should be printed if the test fails.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
|
|
|
Does nothing in release version of the library.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<dbg_break>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void dbg_assert(int test, const char *msg);
|
2011-04-13 18:37:12 +00:00
|
|
|
#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
|
2007-08-22 07:52:33 +00:00
|
|
|
void dbg_assert_imp(const char *filename, int line, int test, const char *msg);
|
|
|
|
|
2012-08-17 16:32:56 +00:00
|
|
|
|
|
|
|
#ifdef __clang_analyzer__
|
|
|
|
#include <assert.h>
|
|
|
|
#undef dbg_assert
|
|
|
|
#define dbg_assert(test,msg) assert(test)
|
|
|
|
#endif
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: dbg_break
|
2008-07-06 11:21:21 +00:00
|
|
|
Breaks into the debugger.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
|
|
|
Does nothing in release version of the library.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<dbg_assert>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void dbg_break();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: dbg_msg
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Prints a debug message.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
sys - A string that describes what system the message belongs to
|
|
|
|
fmt - A printf styled format string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
2010-05-29 07:25:38 +00:00
|
|
|
Does nothing in release version of the library.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<dbg_assert>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void dbg_msg(const char *sys, const char *fmt, ...);
|
|
|
|
|
|
|
|
/* Group: Memory */
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: mem_alloc
|
2008-07-06 11:21:21 +00:00
|
|
|
Allocates memory.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
size - Size of the needed block.
|
|
|
|
alignment - Alignment for the block.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns a pointer to the newly allocated block. Returns a
|
|
|
|
null pointer if the memory couldn't be allocated.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
|
|
|
- Passing 0 to size will allocated the smallest amount possible
|
|
|
|
and return a unique pointer.
|
|
|
|
|
|
|
|
See Also:
|
|
|
|
<mem_free>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment);
|
|
|
|
#define mem_alloc(s,a) mem_alloc_debug(__FILE__, __LINE__, (s), (a))
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: mem_free
|
2008-07-06 11:21:21 +00:00
|
|
|
Frees a block allocated through <mem_alloc>.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
|
|
|
- In the debug version of the library the function will assert if
|
|
|
|
a non-valid block is passed, like a null pointer or a block that
|
|
|
|
isn't allocated.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<mem_alloc>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void mem_free(void *block);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: mem_copy
|
|
|
|
Copies a a memory block.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
dest - Destination.
|
|
|
|
source - Source to copy.
|
|
|
|
size - Size of the block to copy.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
|
|
|
- This functions DOES NOT handles cases where source and
|
|
|
|
destination is overlapping.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<mem_move>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void mem_copy(void *dest, const void *source, unsigned size);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: mem_move
|
2008-07-06 11:21:21 +00:00
|
|
|
Copies a a memory block
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
2008-07-06 11:21:21 +00:00
|
|
|
dest - Destination
|
|
|
|
source - Source to copy
|
|
|
|
size - Size of the block to copy
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Remarks:
|
2008-07-06 11:21:21 +00:00
|
|
|
- This functions handles cases where source and destination
|
|
|
|
is overlapping
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
See Also:
|
|
|
|
<mem_copy>
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void mem_move(void *dest, const void *source, unsigned size);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: mem_zero
|
2008-07-06 11:21:21 +00:00
|
|
|
Sets a complete memory block to 0
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
2008-07-06 11:21:21 +00:00
|
|
|
block - Pointer to the block to zero out
|
|
|
|
size - Size of the block
|
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void mem_zero(void *block, unsigned size);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: mem_comp
|
|
|
|
Compares two blocks of memory
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
a - First block of data
|
|
|
|
b - Second block of data
|
|
|
|
size - Size of the data to compare
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
|
|
|
<0 - Block a is lesser then block b
|
|
|
|
0 - Block a is equal to block b
|
|
|
|
>0 - Block a is greater then block b
|
|
|
|
*/
|
|
|
|
int mem_comp(const void *a, const void *b, int size);
|
|
|
|
|
2008-10-06 16:44:34 +00:00
|
|
|
/*
|
|
|
|
Function: mem_check
|
|
|
|
Validates the heap
|
|
|
|
Will trigger a assert if memory has failed.
|
|
|
|
*/
|
2008-10-07 16:17:58 +00:00
|
|
|
int mem_check_imp();
|
2011-04-13 18:37:12 +00:00
|
|
|
#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed")
|
2008-10-06 16:44:34 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: File IO */
|
2007-08-22 07:52:33 +00:00
|
|
|
enum {
|
|
|
|
IOFLAG_READ = 1,
|
|
|
|
IOFLAG_WRITE = 2,
|
|
|
|
IOFLAG_RANDOM = 4,
|
|
|
|
|
2007-08-25 08:48:24 +00:00
|
|
|
IOSEEK_START = 0,
|
2007-08-22 07:52:33 +00:00
|
|
|
IOSEEK_CUR = 1,
|
|
|
|
IOSEEK_END = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct IOINTERNAL *IOHANDLE;
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_open
|
2008-02-02 12:38:36 +00:00
|
|
|
Opens a file.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
filename - File to open.
|
|
|
|
flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns a handle to the file on success and 0 on failure.
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
IOHANDLE io_open(const char *filename, int flags);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_read
|
2008-02-02 12:38:36 +00:00
|
|
|
Reads data into a buffer from a file.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
io - Handle to the file to read data from.
|
|
|
|
buffer - Pointer to the buffer that will recive the data.
|
|
|
|
size - Number of bytes to read from the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Number of bytes read.
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_skip
|
2008-02-02 12:38:36 +00:00
|
|
|
Skips data in a file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
size - Number of bytes to skip.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Number of bytes skipped.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2010-09-03 19:17:32 +00:00
|
|
|
unsigned io_skip(IOHANDLE io, int size);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_write
|
2008-07-06 11:21:21 +00:00
|
|
|
Writes data from a buffer to file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
buffer - Pointer to the data that should be written.
|
|
|
|
size - Number of bytes to write.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Number of bytes written.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
|
|
|
|
|
2011-12-29 22:36:53 +00:00
|
|
|
/*
|
|
|
|
Function: io_write_newline
|
|
|
|
Writes newline to file.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of bytes written.
|
|
|
|
*/
|
|
|
|
unsigned io_write_newline(IOHANDLE io);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_seek
|
2008-02-02 12:38:36 +00:00
|
|
|
Seeks to a specified offset in the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
offset - Offset from pos to stop.
|
|
|
|
origin - Position to start searching from.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
int io_seek(IOHANDLE io, int offset, int origin);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_tell
|
2008-02-02 12:38:36 +00:00
|
|
|
Gets the current position in the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns the current position. -1L if an error occured.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
long int io_tell(IOHANDLE io);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_length
|
2008-02-02 12:38:36 +00:00
|
|
|
Gets the total length of the file. Resetting cursor to the beginning
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns the total size. -1L if an error occured.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
long int io_length(IOHANDLE io);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: io_close
|
2008-02-02 12:38:36 +00:00
|
|
|
Closes a file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
int io_close(IOHANDLE io);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2008-03-10 00:48:45 +00:00
|
|
|
Function: io_flush
|
|
|
|
Empties all buffers and writes all pending data.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-10 00:48:45 +00:00
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-10 00:48:45 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2008-03-10 00:48:45 +00:00
|
|
|
int io_flush(IOHANDLE io);
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: io_stdin
|
|
|
|
Returns an <IOHANDLE> to the standard input.
|
|
|
|
*/
|
|
|
|
IOHANDLE io_stdin();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: io_stdout
|
|
|
|
Returns an <IOHANDLE> to the standard output.
|
|
|
|
*/
|
|
|
|
IOHANDLE io_stdout();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: io_stderr
|
|
|
|
Returns an <IOHANDLE> to the standard error.
|
|
|
|
*/
|
|
|
|
IOHANDLE io_stderr();
|
|
|
|
|
|
|
|
|
|
|
|
/* Group: Threads */
|
|
|
|
|
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: thread_sleep
|
2008-07-06 11:21:21 +00:00
|
|
|
Suspends the current thread for a given period.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Parameters:
|
|
|
|
milliseconds - Number of milliseconds to sleep.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
void thread_sleep(int milliseconds);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: thread_create
|
|
|
|
Creates a new thread.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
threadfunc - Entry point for the new thread.
|
|
|
|
user - Pointer to pass to the thread.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
void *thread_create(void (*threadfunc)(void *), void *user);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: thread_wait
|
|
|
|
Waits for a thread to be done or destroyed.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
thread - Thread to wait for.
|
|
|
|
*/
|
|
|
|
void thread_wait(void *thread);
|
|
|
|
|
|
|
|
/*
|
2010-05-29 07:25:38 +00:00
|
|
|
Function: thread_destroy
|
2008-07-06 11:21:21 +00:00
|
|
|
Destroys a thread.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
thread - Thread to destroy.
|
|
|
|
*/
|
|
|
|
void thread_destroy(void *thread);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: thread_yeild
|
|
|
|
Yeild the current threads execution slice.
|
|
|
|
*/
|
|
|
|
void thread_yield();
|
|
|
|
|
2011-05-01 13:48:09 +00:00
|
|
|
/*
|
|
|
|
Function: thread_detach
|
|
|
|
Puts the thread in the detached thread, guaranteeing that
|
|
|
|
resources of the thread will be freed immediately when the
|
|
|
|
thread terminates.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
thread - Thread to detach
|
|
|
|
*/
|
|
|
|
void thread_detach(void *thread);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/* Group: Locks */
|
2007-10-04 09:49:38 +00:00
|
|
|
typedef void* LOCK;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
LOCK lock_create();
|
|
|
|
void lock_destroy(LOCK lock);
|
|
|
|
|
2007-10-02 16:19:25 +00:00
|
|
|
int lock_try(LOCK lock);
|
|
|
|
void lock_wait(LOCK lock);
|
2007-08-22 07:52:33 +00:00
|
|
|
void lock_release(LOCK lock);
|
|
|
|
|
2012-01-01 14:56:28 +00:00
|
|
|
|
|
|
|
/* Group: Semaphores */
|
|
|
|
|
2012-06-10 10:14:41 +00:00
|
|
|
#if !defined(CONF_PLATFORM_MACOSX)
|
|
|
|
#if defined(CONF_FAMILY_UNIX)
|
|
|
|
#include <semaphore.h>
|
|
|
|
typedef sem_t SEMAPHORE;
|
|
|
|
#elif defined(CONF_FAMILY_WINDOWS)
|
|
|
|
typedef void* SEMAPHORE;
|
|
|
|
#else
|
|
|
|
#error missing sempahore implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void semaphore_init(SEMAPHORE *sem);
|
|
|
|
void semaphore_wait(SEMAPHORE *sem);
|
|
|
|
void semaphore_signal(SEMAPHORE *sem);
|
|
|
|
void semaphore_destroy(SEMAPHORE *sem);
|
2012-01-01 14:56:28 +00:00
|
|
|
#endif
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: Timer */
|
2007-10-06 17:01:06 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
/* if compiled with -pedantic-errors it will complain about long
|
|
|
|
not being a C90 thing.
|
|
|
|
*/
|
|
|
|
__extension__ typedef long long int64;
|
|
|
|
#else
|
2007-08-22 07:52:33 +00:00
|
|
|
typedef long long int64;
|
2007-10-06 17:01:06 +00:00
|
|
|
#endif
|
2014-11-09 23:08:50 +00:00
|
|
|
|
|
|
|
void set_new_tick();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: time_get
|
2008-07-06 11:21:21 +00:00
|
|
|
Fetches a sample from a high resolution timer.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Current value of the timer.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
To know how fast the timer is ticking, see <time_freq>.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
int64 time_get();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: time_freq
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns the frequency of the high resolution timer.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns the frequency of the high resolution timer.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2007-08-22 07:52:33 +00:00
|
|
|
int64 time_freq();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: time_timestamp
|
|
|
|
Retrives the current time as a UNIX timestamp
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
|
|
|
The time as a UNIX timestamp
|
|
|
|
*/
|
2011-12-29 22:36:53 +00:00
|
|
|
int time_timestamp();
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
/* Group: Network General */
|
2011-03-28 18:11:28 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int ipv4sock;
|
|
|
|
int ipv6sock;
|
|
|
|
} NETSOCKET;
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2011-03-28 18:11:28 +00:00
|
|
|
NETADDR_MAXSTRSIZE = 1+(8*4+7)+1+1+5+1, // [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:XXXXX
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
NETTYPE_INVALID = 0,
|
|
|
|
NETTYPE_IPV4 = 1,
|
|
|
|
NETTYPE_IPV6 = 2,
|
2011-03-28 18:11:28 +00:00
|
|
|
NETTYPE_LINK_BROADCAST = 4,
|
|
|
|
NETTYPE_ALL = NETTYPE_IPV4|NETTYPE_IPV6
|
2007-08-22 07:52:33 +00:00
|
|
|
};
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int type;
|
|
|
|
unsigned char ip[16];
|
|
|
|
unsigned short port;
|
|
|
|
} NETADDR;
|
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
/*
|
|
|
|
Function: net_init
|
|
|
|
Initiates network functionallity.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success,
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Remarks:
|
|
|
|
You must call this function before using any other network
|
|
|
|
functions.
|
|
|
|
*/
|
|
|
|
int net_init();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2007-08-22 07:52:33 +00:00
|
|
|
Function: net_host_lookup
|
2008-08-05 21:37:33 +00:00
|
|
|
Does a hostname lookup by name and fills out the passed
|
|
|
|
NETADDR struct with the recieved details.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
0 on success.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_host_lookup(const char *hostname, NETADDR *addr, int types);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
/*
|
|
|
|
Function: net_addr_comp
|
|
|
|
Compares two network addresses.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
a - Address to compare
|
|
|
|
b - Address to compare to.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
<0 - Address a is lesser then address b
|
|
|
|
0 - Address a is equal to address b
|
|
|
|
>0 - Address a is greater then address b
|
|
|
|
*/
|
|
|
|
int net_addr_comp(const NETADDR *a, const NETADDR *b);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_addr_str
|
|
|
|
Turns a network address into a representive string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
addr - Address to turn into a string.
|
|
|
|
string - Buffer to fill with the string.
|
|
|
|
max_length - Maximum size of the string.
|
2011-12-29 22:36:53 +00:00
|
|
|
add_port - add port to string or not
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Remarks:
|
|
|
|
- The string will always be zero terminated
|
|
|
|
|
|
|
|
*/
|
2011-12-29 22:36:53 +00:00
|
|
|
void net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
2008-09-03 21:02:30 +00:00
|
|
|
/*
|
|
|
|
Function: net_addr_from_str
|
|
|
|
Turns string into a network address.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-09-03 21:02:30 +00:00
|
|
|
Returns:
|
|
|
|
0 on success
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-09-03 21:02:30 +00:00
|
|
|
Parameters:
|
|
|
|
addr - Address to fill in.
|
|
|
|
string - String to parse.
|
|
|
|
*/
|
|
|
|
int net_addr_from_str(NETADDR *addr, const char *string);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: Network UDP */
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_udp_create
|
|
|
|
Creates a UDP socket and binds it to a port.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
2008-08-05 21:37:33 +00:00
|
|
|
bindaddr - Address to bind the socket to.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
On success it returns an handle to the socket. On failure it
|
|
|
|
returns NETSOCKET_INVALID.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
NETSOCKET net_udp_create(NETADDR bindaddr);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_udp_send
|
|
|
|
Sends a packet over an UDP socket.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to use.
|
|
|
|
addr - Where to send the packet.
|
|
|
|
data - Pointer to the packet data to send.
|
|
|
|
size - Size of the packet.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
On success it returns the number of bytes sent. Returns -1
|
|
|
|
on error.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_udp_recv
|
|
|
|
Recives a packet over an UDP socket.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to use.
|
2008-07-06 11:21:21 +00:00
|
|
|
addr - Pointer to an NETADDR that will recive the address.
|
2007-08-22 07:52:33 +00:00
|
|
|
data - Pointer to a buffer that will recive the data.
|
|
|
|
maxsize - Maximum size to recive.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
On success it returns the number of bytes recived. Returns -1
|
|
|
|
on error.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_udp_close
|
|
|
|
Closes an UDP socket.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to close.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success. -1 on error.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_udp_close(NETSOCKET sock);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: Network TCP */
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_create
|
2008-08-05 21:37:33 +00:00
|
|
|
Creates a TCP socket.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
bindaddr - Address to bind the socket to.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
On success it returns an handle to the socket. On failure it returns NETSOCKET_INVALID.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2011-07-06 16:20:46 +00:00
|
|
|
NETSOCKET net_tcp_create(NETADDR bindaddr);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_listen
|
2008-08-05 21:37:33 +00:00
|
|
|
Makes the socket start listening for new connections.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
sock - Socket to start listen to.
|
|
|
|
backlog - Size of the queue of incomming connections to keep.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_tcp_listen(NETSOCKET sock, int backlog);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_accept
|
2008-08-05 21:37:33 +00:00
|
|
|
Polls a listning socket for a new connection.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
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).
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns a non-negative integer on success. Negative integer on failure.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2008-08-05 21:37:33 +00:00
|
|
|
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_connect
|
2008-08-05 21:37:33 +00:00
|
|
|
Connects one socket to another.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
sock - Socket to connect.
|
|
|
|
addr - Address to connect to.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2008-08-05 21:37:33 +00:00
|
|
|
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_send
|
2008-08-05 21:37:33 +00:00
|
|
|
Sends data to a TCP stream.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
sock - Socket to send data to.
|
|
|
|
data - Pointer to the data to send.
|
|
|
|
size - Size of the data to send.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Number of bytes sent. Negative value on failure.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_tcp_send(NETSOCKET sock, const void *data, int size);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_recv
|
2008-08-05 21:37:33 +00:00
|
|
|
Recvives data from a TCP stream.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
sock - Socket to recvive data from.
|
|
|
|
data - Pointer to a buffer to write the data to
|
|
|
|
max_size - Maximum of data to write to the buffer.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
2008-09-23 07:43:41 +00:00
|
|
|
Number of bytes recvived. Negative value on failure. When in
|
|
|
|
non-blocking mode, it returns 0 when there is no more data to
|
|
|
|
be fetched.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_tcp_close
|
2008-08-05 21:37:33 +00:00
|
|
|
Closes a TCP socket.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Parameters:
|
|
|
|
sock - Socket to close.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success. Negative value on failure.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int net_tcp_close(NETSOCKET sock);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: Strings */
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_append
|
|
|
|
Appends a string to another.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
dst - Pointer to a buffer that contains a string.
|
|
|
|
src - String to append.
|
|
|
|
dst_size - Size of the buffer of the dst string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
- Garantees that dst string will contain zero-termination.
|
|
|
|
*/
|
|
|
|
void str_append(char *dst, const char *src, int dst_size);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_copy
|
|
|
|
Copies a string to another.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
dst - Pointer to a buffer that shall recive the string.
|
|
|
|
src - String to be copied.
|
|
|
|
dst_size - Size of the buffer dst.
|
2007-09-25 19:48:52 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
- Garantees that dst string will contain zero-termination.
|
|
|
|
*/
|
|
|
|
void str_copy(char *dst, const char *src, int dst_size);
|
2008-02-10 21:54:52 +00:00
|
|
|
|
2008-11-08 08:27:11 +00:00
|
|
|
/*
|
|
|
|
Function: str_length
|
|
|
|
Returns the length of a zero terminated string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-11-08 08:27:11 +00:00
|
|
|
Parameters:
|
|
|
|
str - Pointer to the string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-11-08 08:27:11 +00:00
|
|
|
Returns:
|
|
|
|
Length of string in bytes excluding the zero termination.
|
|
|
|
*/
|
|
|
|
int str_length(const char *str);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_format
|
|
|
|
Performs printf formating into a buffer.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
buffer - Pointer to the buffer to recive the formated string.
|
|
|
|
buffer_size - Size of the buffer.
|
|
|
|
format - printf formating string.
|
|
|
|
... - Parameters for the formating.
|
2008-01-29 21:39:41 +00:00
|
|
|
|
2013-07-21 02:52:23 +00:00
|
|
|
Returns:
|
|
|
|
Length of written string
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
- See the C manual for syntax for the printf formating string.
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
- Garantees that dst string will contain zero-termination.
|
|
|
|
*/
|
2013-07-21 02:52:23 +00:00
|
|
|
int str_format(char *buffer, int buffer_size, const char *format, ...);
|
2008-01-29 21:39:41 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_sanitize_strong
|
|
|
|
Replaces all characters below 32 and above 127 with whitespace.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
str - String to sanitize.
|
2008-02-11 21:49:26 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
2008-02-24 16:03:58 +00:00
|
|
|
void str_sanitize_strong(char *str);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-08-12 13:22:07 +00:00
|
|
|
/*
|
|
|
|
Function: str_sanitize_cc
|
|
|
|
Replaces all characters below 32 with whitespace.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-08-12 13:22:07 +00:00
|
|
|
Parameters:
|
|
|
|
str - String to sanitize.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
void str_sanitize_cc(char *str);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_sanitize
|
2010-08-12 13:22:07 +00:00
|
|
|
Replaces all characters below 32 with whitespace with
|
|
|
|
exception to \t, \n and \r.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
str - String to sanitize.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
2008-02-24 16:03:58 +00:00
|
|
|
void str_sanitize(char *str);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-10-25 16:41:15 +00:00
|
|
|
/*
|
|
|
|
Function: str_skip_to_whitespace
|
|
|
|
Skips leading non-whitespace characters(all but ' ', '\t', '\n', '\r').
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-25 16:41:15 +00:00
|
|
|
Parameters:
|
|
|
|
str - Pointer to the string.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Pointer to the first whitespace character found
|
|
|
|
within the string.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
char *str_skip_to_whitespace(char *str);
|
|
|
|
|
2010-08-12 13:22:07 +00:00
|
|
|
/*
|
|
|
|
Function: str_skip_whitespaces
|
|
|
|
Skips leading whitespace characters(' ', '\t', '\n', '\r').
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-08-12 13:22:07 +00:00
|
|
|
Parameters:
|
|
|
|
str - Pointer to the string.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Pointer to the first non-whitespace character found
|
|
|
|
within the string.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
char *str_skip_whitespaces(char *str);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_comp_nocase
|
|
|
|
Compares to strings case insensitive.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
<0 - String a is lesser then string b
|
2008-07-06 11:21:21 +00:00
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater then string b
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Only garanted to work with a-z/A-Z.
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
2008-03-29 17:20:21 +00:00
|
|
|
int str_comp_nocase(const char *a, const char *b);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2011-06-09 21:28:20 +00:00
|
|
|
/*
|
|
|
|
Function: str_comp_nocase_num
|
|
|
|
Compares up to num characters of two strings case insensitive.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
|
|
|
num - Maximum characters to compare
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
<0 - String a is lesser than string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater than string b
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Only garanted to work with a-z/A-Z.
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
int str_comp_nocase_num(const char *a, const char *b, const int num);
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
/*
|
2010-09-22 14:16:07 +00:00
|
|
|
Function: str_comp
|
2009-06-13 16:54:04 +00:00
|
|
|
Compares to strings case sensitive.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 16:54:04 +00:00
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
Returns:
|
2009-06-13 16:54:04 +00:00
|
|
|
<0 - String a is lesser then string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater then string b
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
int str_comp(const char *a, const char *b);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
/*
|
2010-09-22 14:16:07 +00:00
|
|
|
Function: str_comp_num
|
2010-05-29 07:25:38 +00:00
|
|
|
Compares up to num characters of two strings case sensitive.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
|
|
|
num - Maximum characters to compare
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
Returns:
|
2010-05-29 07:25:38 +00:00
|
|
|
<0 - String a is lesser then string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater then string b
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
int str_comp_num(const char *a, const char *b, const int num);
|
|
|
|
|
2010-09-28 22:53:53 +00:00
|
|
|
/*
|
|
|
|
Function: str_comp_filenames
|
|
|
|
Compares two strings case sensitive, digit chars will be compared as numbers.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-09-28 22:53:53 +00:00
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
Returns:
|
2010-09-28 22:53:53 +00:00
|
|
|
<0 - String a is lesser then string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater then string b
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
int str_comp_filenames(const char *a, const char *b);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_find_nocase
|
|
|
|
Finds a string inside another string case insensitive.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
haystack - String to search in
|
|
|
|
needle - String to search for
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
|
|
|
A pointer into haystack where the needle was found.
|
|
|
|
Returns NULL of needle could not be found.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Only garanted to work with a-z/A-Z.
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
2008-03-29 17:20:21 +00:00
|
|
|
const char *str_find_nocase(const char *haystack, const char *needle);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2009-06-13 16:54:04 +00:00
|
|
|
/*
|
|
|
|
Function: str_find
|
|
|
|
Finds a string inside another string case sensitive.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
haystack - String to search in
|
|
|
|
needle - String to search for
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 16:54:04 +00:00
|
|
|
Returns:
|
|
|
|
A pointer into haystack where the needle was found.
|
|
|
|
Returns NULL of needle could not be found.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
const char *str_find(const char *haystack, const char *needle);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_hex
|
|
|
|
Takes a datablock and generates a hexstring of it.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
dst - Buffer to fill with hex data
|
|
|
|
dst_size - size of the buffer
|
|
|
|
data - Data to turn into hex
|
|
|
|
data - Size of the data
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The desination buffer will be zero-terminated
|
|
|
|
*/
|
2008-04-05 14:50:43 +00:00
|
|
|
void str_hex(char *dst, int dst_size, const void *data, int data_size);
|
2008-02-24 16:03:58 +00:00
|
|
|
|
2010-12-07 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Function: str_timestamp
|
|
|
|
Copies a time stamp in the format year-month-day_hour-minute-second to the string.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
buffer - Pointer to a buffer that shall receive the time stamp string.
|
|
|
|
buffer_size - Size of the buffer.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Guarantees that buffer string will contain zero-termination.
|
|
|
|
*/
|
|
|
|
void str_timestamp(char *buffer, int buffer_size);
|
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
/* Group: Filesystem */
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: fs_listdir
|
|
|
|
Lists the files in a directory
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
dir - Directory to list
|
|
|
|
cb - Callback function to call for each entry
|
2010-09-24 11:38:03 +00:00
|
|
|
type - Type of the directory
|
2008-07-06 11:21:21 +00:00
|
|
|
user - Pointer to give to the callback
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
Always returns 0.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2011-02-21 10:23:30 +00:00
|
|
|
typedef int (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user);
|
2010-09-24 11:38:03 +00:00
|
|
|
int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: fs_makedir
|
|
|
|
Creates a directory
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
|
|
|
path - Directory to create
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns 0 on success. Negative value on failure.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
Does not create several directories if needed. "a/b/c" will result
|
|
|
|
in a failure if b or a does not exist.
|
|
|
|
*/
|
|
|
|
int fs_makedir(const char *path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: fs_storage_path
|
|
|
|
Fetches per user configuration directory.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Returns:
|
2008-08-05 21:37:33 +00:00
|
|
|
Returns 0 on success. Negative value on failure.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
|
|
|
- Returns ~/.appname on UNIX based systems
|
2008-08-05 21:37:33 +00:00
|
|
|
- Returns ~/Library/Applications Support/appname on Mac OS X
|
2008-07-06 11:21:21 +00:00
|
|
|
- Returns %APPDATA%/Appname on Windows based systems
|
|
|
|
*/
|
|
|
|
int fs_storage_path(const char *appname, char *path, int max);
|
|
|
|
|
2008-10-01 17:16:22 +00:00
|
|
|
/*
|
|
|
|
Function: fs_is_dir
|
|
|
|
Checks if directory exists
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-10-01 17:16:22 +00:00
|
|
|
Returns:
|
|
|
|
Returns 1 on success, 0 on failure.
|
|
|
|
*/
|
|
|
|
int fs_is_dir(const char *path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: fs_chdir
|
|
|
|
Changes current working directory
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-10-01 17:16:22 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success, 1 on failure.
|
|
|
|
*/
|
|
|
|
int fs_chdir(const char *path);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2010-12-11 22:10:13 +00:00
|
|
|
/*
|
|
|
|
Function: fs_getcwd
|
|
|
|
Gets the current working directory.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-11 22:10:13 +00:00
|
|
|
Returns:
|
|
|
|
Returns a pointer to the buffer on success, 0 on failure.
|
|
|
|
*/
|
|
|
|
char *fs_getcwd(char *buffer, int buffer_size);
|
|
|
|
|
2010-09-12 11:15:59 +00:00
|
|
|
/*
|
|
|
|
Function: fs_parent_dir
|
|
|
|
Get the parent directory of a directory
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-09-12 11:15:59 +00:00
|
|
|
Parameters:
|
2010-09-16 10:48:32 +00:00
|
|
|
path - The directory string
|
|
|
|
|
2010-10-07 21:51:07 +00:00
|
|
|
Returns:
|
|
|
|
Returns 0 on success, 1 on failure.
|
|
|
|
|
2010-09-16 10:48:32 +00:00
|
|
|
Remarks:
|
|
|
|
- The string is treated as zero-termineted string.
|
2010-09-12 11:15:59 +00:00
|
|
|
*/
|
2010-10-07 21:51:07 +00:00
|
|
|
int fs_parent_dir(char *path);
|
2010-09-12 11:15:59 +00:00
|
|
|
|
2010-12-07 23:13:59 +00:00
|
|
|
/*
|
|
|
|
Function: fs_remove
|
|
|
|
Deletes the file with the specified name.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-07 23:13:59 +00:00
|
|
|
Parameters:
|
|
|
|
filename - The file to delete
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns 0 on success, 1 on failure.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
int fs_remove(const char *filename);
|
|
|
|
|
2010-12-07 23:09:18 +00:00
|
|
|
/*
|
|
|
|
Function: fs_rename
|
|
|
|
Renames the file or directory. If the paths differ the file will be moved.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-07 23:09:18 +00:00
|
|
|
Parameters:
|
|
|
|
oldname - The actual name
|
|
|
|
newname - The new name
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns 0 on success, 1 on failure.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
int fs_rename(const char *oldname, const char *newname);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Group: Undocumented
|
|
|
|
*/
|
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_tcp_connect_non_blocking
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
2011-07-06 16:20:46 +00:00
|
|
|
int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
/*
|
2011-07-06 16:20:46 +00:00
|
|
|
Function: net_set_non_blocking
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
2011-07-06 16:20:46 +00:00
|
|
|
int net_set_non_blocking(NETSOCKET sock);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
/*
|
2011-07-06 16:20:46 +00:00
|
|
|
Function: net_set_non_blocking
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
2011-07-06 16:20:46 +00:00
|
|
|
int net_set_blocking(NETSOCKET sock);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_errno
|
|
|
|
|
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
|
|
|
int net_errno();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_would_block
|
|
|
|
|
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
|
|
|
int net_would_block();
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
int net_socket_read_wait(NETSOCKET sock, int time);
|
|
|
|
|
2011-03-05 10:46:24 +00:00
|
|
|
void mem_debug_dump(IOHANDLE file);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
void swap_endian(void *data, unsigned elem_size, unsigned num);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
typedef void (*DBG_LOGGER)(const char *line);
|
2008-03-10 00:48:45 +00:00
|
|
|
void dbg_logger(DBG_LOGGER logger);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2014-09-11 19:38:23 +00:00
|
|
|
#if !defined(CONF_PLATFORM_MACOSX)
|
2014-09-09 21:02:05 +00:00
|
|
|
void dbg_enable_threaded();
|
2014-09-11 19:38:23 +00:00
|
|
|
#endif
|
2008-03-10 00:48:45 +00:00
|
|
|
void dbg_logger_stdout();
|
|
|
|
void dbg_logger_debugger();
|
|
|
|
void dbg_logger_file(const char *filename);
|
|
|
|
|
2008-10-02 12:29:19 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int allocated;
|
|
|
|
int active_allocations;
|
|
|
|
int total_allocations;
|
|
|
|
} MEMSTATS;
|
|
|
|
|
|
|
|
const MEMSTATS *mem_stats();
|
|
|
|
|
2008-04-05 14:50:43 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int sent_packets;
|
|
|
|
int sent_bytes;
|
|
|
|
int recv_packets;
|
|
|
|
int recv_bytes;
|
|
|
|
} NETSTATS;
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2008-04-05 14:50:43 +00:00
|
|
|
void net_stats(NETSTATS *stats);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int str_toint(const char *str);
|
|
|
|
float str_tofloat(const char *str);
|
2008-11-08 08:27:11 +00:00
|
|
|
int str_isspace(char c);
|
2009-06-15 08:15:53 +00:00
|
|
|
char str_uppercase(char c);
|
2009-06-15 13:01:04 +00:00
|
|
|
unsigned str_quickhash(const char *str);
|
2008-11-08 08:27:11 +00:00
|
|
|
|
2008-09-30 15:52:15 +00:00
|
|
|
/*
|
|
|
|
Function: gui_messagebox
|
|
|
|
Display plain OS-dependent message box
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-09-30 15:52:15 +00:00
|
|
|
Parameters:
|
|
|
|
title - title of the message box
|
|
|
|
message - text to display
|
|
|
|
*/
|
|
|
|
void gui_messagebox(const char *title, const char *message);
|
|
|
|
|
2014-11-08 19:14:12 +00:00
|
|
|
int str_utf8_isspace(int code);
|
|
|
|
|
2013-04-26 15:10:05 +00:00
|
|
|
const char *str_utf8_skip_whitespaces(const char *str);
|
2009-06-13 08:22:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_rewind
|
|
|
|
Moves a cursor backwards in an utf8 string
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Parameters:
|
|
|
|
str - utf8 string
|
|
|
|
cursor - position in the string
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
New cursor position.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Won't move the cursor less then 0
|
|
|
|
*/
|
|
|
|
int str_utf8_rewind(const char *str, int cursor);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_forward
|
|
|
|
Moves a cursor forwards in an utf8 string
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Parameters:
|
|
|
|
str - utf8 string
|
|
|
|
cursor - position in the string
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Returns:
|
|
|
|
New cursor position.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Won't move the cursor beyond the zero termination marker
|
|
|
|
*/
|
|
|
|
int str_utf8_forward(const char *str, int cursor);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_decode
|
|
|
|
Decodes an utf8 character
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Parameters:
|
|
|
|
ptr - pointer to an utf8 string. this pointer will be moved forward
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Returns:
|
|
|
|
Unicode value for the character. -1 for invalid characters and 0 for end of string.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- This function will also move the pointer forward.
|
|
|
|
*/
|
|
|
|
int str_utf8_decode(const char **ptr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_encode
|
|
|
|
Encode an utf8 character
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Parameters:
|
|
|
|
ptr - Pointer to a buffer that should recive the data. Should be able to hold at least 4 bytes.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Returns:
|
|
|
|
Number of bytes put into the buffer.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Does not do zero termination of the string.
|
|
|
|
*/
|
|
|
|
int str_utf8_encode(char *ptr, int chr);
|
|
|
|
|
2010-09-30 22:55:16 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_check
|
|
|
|
Checks if a strings contains just valid utf8 characters.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-09-30 22:55:16 +00:00
|
|
|
Parameters:
|
|
|
|
str - Pointer to a possible utf8 string.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-09-30 22:55:16 +00:00
|
|
|
Returns:
|
|
|
|
0 - invalid characters found.
|
|
|
|
1 - only valid characters found.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The string is treated as zero-terminated utf8 string.
|
|
|
|
*/
|
|
|
|
int str_utf8_check(const char *str);
|
|
|
|
|
2014-08-22 12:18:16 +00:00
|
|
|
int pid();
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|