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"
|
2018-07-25 14:06:00 +00:00
|
|
|
|
|
|
|
#ifndef __USE_GNU
|
|
|
|
#define __USE_GNU
|
|
|
|
#endif
|
|
|
|
|
2018-04-09 09:56:39 +00:00
|
|
|
#include <stddef.h>
|
2021-06-23 05:05:49 +00:00
|
|
|
#include <stdint.h>
|
2018-04-09 09:56:39 +00:00
|
|
|
#include <stdlib.h>
|
2015-08-22 18:32:02 +00:00
|
|
|
#include <time.h>
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2017-12-20 15:56:34 +00:00
|
|
|
#ifdef CONF_FAMILY_UNIX
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
|
2018-07-25 14:06:00 +00:00
|
|
|
#ifdef CONF_PLATFORM_LINUX
|
2018-12-17 19:49:25 +00:00
|
|
|
#include <netinet/in.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <sys/socket.h>
|
2018-07-25 14:06:00 +00:00
|
|
|
#endif
|
|
|
|
|
2021-06-15 01:24:23 +00:00
|
|
|
#if defined(__cplusplus)
|
2007-08-22 07:52:33 +00:00
|
|
|
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:
|
2017-06-02 18:12:20 +00:00
|
|
|
Does nothing in release version
|
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
|
|
|
*/
|
2017-06-02 18:12:20 +00:00
|
|
|
#ifdef CONF_DEBUG
|
2020-09-26 19:41:58 +00:00
|
|
|
#define dbg_assert(test, msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
|
2017-06-02 18:12:20 +00:00
|
|
|
#else
|
2020-09-26 19:41:58 +00:00
|
|
|
#define dbg_assert(test, msg)
|
2017-06-02 18:12:20 +00:00
|
|
|
#endif
|
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
|
2020-09-26 19:41:58 +00:00
|
|
|
#define dbg_assert(test, msg) assert(test)
|
2012-08-17 16:32:56 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-26 01:58:00 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define GNUC_ATTRIBUTE(x) __attribute__(x)
|
|
|
|
#else
|
|
|
|
#define GNUC_ATTRIBUTE(x)
|
|
|
|
#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:
|
2017-06-02 18:12:20 +00:00
|
|
|
Does nothing in release version
|
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
|
|
|
*/
|
2017-06-02 18:12:20 +00:00
|
|
|
#ifdef CONF_DEBUG
|
|
|
|
#define dbg_break() dbg_break_imp()
|
|
|
|
#else
|
|
|
|
#define dbg_break()
|
|
|
|
#endif
|
2020-04-12 17:56:11 +00:00
|
|
|
void dbg_break_imp(void);
|
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: 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:
|
2017-06-02 18:12:20 +00:00
|
|
|
Also works in release version
|
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
|
|
|
*/
|
2017-07-26 01:58:00 +00:00
|
|
|
void dbg_msg(const char *sys, const char *fmt, ...)
|
2020-09-26 19:41:58 +00:00
|
|
|
GNUC_ATTRIBUTE((format(printf, 2, 3)));
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
/* Group: Memory */
|
|
|
|
|
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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - Block a is less than block b
|
2008-07-06 11:21:21 +00:00
|
|
|
0 - Block a is equal to block b
|
2015-12-19 17:12:45 +00:00
|
|
|
>0 - Block a is greater than block b
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
int mem_comp(const void *a, const void *b, int size);
|
|
|
|
|
|
|
|
/* Group: File IO */
|
2020-09-26 19:41:58 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-08-22 07:52:33 +00:00
|
|
|
IOFLAG_READ = 1,
|
|
|
|
IOFLAG_WRITE = 2,
|
|
|
|
IOFLAG_RANDOM = 4,
|
2015-12-19 17:12:45 +00:00
|
|
|
IOFLAG_APPEND = 8,
|
2007-08-22 07:52:33 +00:00
|
|
|
|
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.
|
2015-12-19 17:12:45 +00:00
|
|
|
flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM, IOFLAG_APPEND.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
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.
|
2018-07-10 09:29:02 +00:00
|
|
|
buffer - Pointer to the buffer that will receive the data.
|
2007-08-22 07:52:33 +00:00
|
|
|
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:
|
2018-02-04 15:00:47 +00:00
|
|
|
Returns the current position. -1L if an error occurred.
|
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:
|
2018-02-04 15:00:47 +00:00
|
|
|
Returns the total size. -1L if an error occurred.
|
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);
|
|
|
|
|
2017-10-10 01:33:54 +00:00
|
|
|
/*
|
|
|
|
Function: io_error
|
2018-02-04 15:00:47 +00:00
|
|
|
Checks whether an error occurred during I/O with the file.
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns nonzero on error, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int io_error(IOHANDLE io);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: io_stdin
|
|
|
|
Returns an <IOHANDLE> to the standard input.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
IOHANDLE io_stdin(void);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: io_stdout
|
|
|
|
Returns an <IOHANDLE> to the standard output.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
IOHANDLE io_stdout(void);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: io_stderr
|
|
|
|
Returns an <IOHANDLE> to the standard error.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
IOHANDLE io_stderr(void);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2017-10-10 01:33:54 +00:00
|
|
|
typedef struct ASYNCIO ASYNCIO;
|
|
|
|
|
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_new
|
2017-10-10 01:33:54 +00:00
|
|
|
Wraps a <IOHANDLE> for asynchronous writing.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
io - Handle to the file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns the handle for asynchronous writing.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
ASYNCIO *aio_new(IOHANDLE io);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
2017-11-26 16:01:11 +00:00
|
|
|
/*
|
|
|
|
Function: aio_lock
|
|
|
|
Locks the ASYNCIO structure so it can't be written into by
|
|
|
|
other threads.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
*/
|
|
|
|
void aio_lock(ASYNCIO *aio);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: aio_unlock
|
|
|
|
Unlocks the ASYNCIO structure after finishing the contiguous
|
|
|
|
write.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
*/
|
|
|
|
void aio_unlock(ASYNCIO *aio);
|
|
|
|
|
2017-10-10 01:33:54 +00:00
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_write
|
2017-10-10 01:33:54 +00:00
|
|
|
Queues a chunk of data for writing.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
buffer - Pointer to the data that should be written.
|
|
|
|
size - Number of bytes to write.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
void aio_write(ASYNCIO *aio, const void *buffer, unsigned size);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_write_newline
|
2017-10-10 01:33:54 +00:00
|
|
|
Queues a newline for writing.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
void aio_write_newline(ASYNCIO *aio);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
2017-11-26 16:01:11 +00:00
|
|
|
/*
|
|
|
|
Function: aio_write_unlocked
|
|
|
|
Queues a chunk of data for writing. The ASYNCIO struct must be
|
|
|
|
locked using `aio_lock` first.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
buffer - Pointer to the data that should be written.
|
|
|
|
size - Number of bytes to write.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: aio_write_newline_unlocked
|
|
|
|
Queues a newline for writing. The ASYNCIO struct must be locked
|
|
|
|
using `aio_lock` first.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void aio_write_newline_unlocked(ASYNCIO *aio);
|
|
|
|
|
2017-10-10 01:33:54 +00:00
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_error
|
2018-02-04 15:00:47 +00:00
|
|
|
Checks whether errors have occurred during the asynchronous
|
2017-10-10 01:33:54 +00:00
|
|
|
writing.
|
|
|
|
|
|
|
|
Call this function regularly to see if there are errors. Call
|
2017-10-13 00:48:42 +00:00
|
|
|
this function after <aio_wait> to see if the process of writing
|
|
|
|
to the file succeeded.
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
Returns:
|
2018-02-04 15:00:47 +00:00
|
|
|
Returns 0 if no error occurred, and nonzero on error.
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
int aio_error(ASYNCIO *aio);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_close
|
2017-10-10 01:33:54 +00:00
|
|
|
Queues file closing.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
void aio_close(ASYNCIO *aio);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_wait
|
2017-10-10 01:33:54 +00:00
|
|
|
Wait for the asynchronous operations to complete.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
void aio_wait(ASYNCIO *aio);
|
2017-10-10 01:33:54 +00:00
|
|
|
|
|
|
|
/*
|
2017-10-13 00:48:42 +00:00
|
|
|
Function: aio_free
|
2017-10-10 01:33:54 +00:00
|
|
|
Frees the resources associated to the asynchronous file handle.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
aio - Handle to the file.
|
|
|
|
|
|
|
|
*/
|
2017-10-13 00:48:42 +00:00
|
|
|
void aio_free(ASYNCIO *aio);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/* 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:
|
2018-12-17 19:05:50 +00:00
|
|
|
microseconds - Number of microseconds to sleep.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2018-12-17 19:05:50 +00:00
|
|
|
void thread_sleep(int microseconds);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
2015-04-07 17:07:38 +00:00
|
|
|
Function: thread_init
|
2008-07-06 11:21:21 +00:00
|
|
|
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.
|
2019-03-19 10:44:16 +00:00
|
|
|
name - name describing the use of the thread
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2019-03-19 10:44:16 +00:00
|
|
|
void *thread_init(void (*threadfunc)(void *), void *user, const char *name);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
2017-10-09 22:08:24 +00:00
|
|
|
Function: thread_yield
|
2017-08-31 17:13:55 +00:00
|
|
|
Yield the current threads execution slice.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
void thread_yield(void);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
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
|
|
|
|
2019-03-19 10:44:16 +00:00
|
|
|
/*
|
|
|
|
Function: thread_init_and_detach
|
|
|
|
Creates a new thread and if it succeeded detaches it.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
threadfunc - Entry point for the new thread.
|
|
|
|
user - Pointer to pass to the thread.
|
|
|
|
name - name describing the use of the thread
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns the thread if no error occured, 0 on error.
|
|
|
|
*/
|
|
|
|
void *thread_init_and_detach(void (*threadfunc)(void *), void *user, const char *name);
|
|
|
|
|
2020-12-02 18:11:19 +00:00
|
|
|
// Enable thread safety attributes only with clang.
|
|
|
|
// The attributes can be safely erased when compiling with other compilers.
|
|
|
|
#if defined(__clang__) && (!defined(SWIG))
|
|
|
|
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
|
|
|
|
#else
|
|
|
|
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CAPABILITY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
|
|
|
|
|
|
|
|
#define SCOPED_CAPABILITY \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
|
|
|
|
|
|
|
|
#define GUARDED_BY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
|
|
|
|
|
|
|
|
#define PT_GUARDED_BY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
|
|
|
|
|
|
|
|
#define ACQUIRED_BEFORE(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define ACQUIRED_AFTER(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define REQUIRES(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define REQUIRES_SHARED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define ACQUIRE(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define ACQUIRE_SHARED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define RELEASE(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define RELEASE_SHARED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define RELEASE_GENERIC(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define TRY_ACQUIRE(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define TRY_ACQUIRE_SHARED(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define EXCLUDES(...) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
|
|
|
|
|
|
|
|
#define ASSERT_CAPABILITY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
|
|
|
|
|
|
|
|
#define ASSERT_SHARED_CAPABILITY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
|
|
|
|
|
|
|
|
#define RETURN_CAPABILITY(x) \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
|
|
|
|
|
|
|
|
#define NO_THREAD_SAFETY_ANALYSIS \
|
|
|
|
THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/* Group: Locks */
|
2020-12-02 18:11:19 +00:00
|
|
|
typedef CAPABILITY("mutex") void *LOCK;
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2020-04-12 17:56:11 +00:00
|
|
|
LOCK lock_create(void);
|
2007-08-22 07:52:33 +00:00
|
|
|
void lock_destroy(LOCK lock);
|
|
|
|
|
2020-12-02 18:11:19 +00:00
|
|
|
int lock_trylock(LOCK lock) TRY_ACQUIRE(1, lock);
|
|
|
|
void lock_wait(LOCK lock) ACQUIRE(lock);
|
|
|
|
void lock_unlock(LOCK lock) RELEASE(lock);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2012-01-01 14:56:28 +00:00
|
|
|
/* Group: Semaphores */
|
2017-08-31 17:13:55 +00:00
|
|
|
#if defined(CONF_FAMILY_WINDOWS)
|
2020-09-26 19:41:58 +00:00
|
|
|
typedef void *SEMAPHORE;
|
2021-02-12 12:40:29 +00:00
|
|
|
#elif defined(CONF_PLATFORM_MACOS)
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <semaphore.h>
|
|
|
|
typedef sem_t *SEMAPHORE;
|
2017-08-31 17:13:55 +00:00
|
|
|
#elif defined(CONF_FAMILY_UNIX)
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <semaphore.h>
|
|
|
|
typedef sem_t SEMAPHORE;
|
2017-08-31 08:59:12 +00:00
|
|
|
#else
|
2020-09-26 19:41:58 +00:00
|
|
|
#error not implemented on this platform
|
2012-01-01 14:56:28 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-31 10:30:42 +00:00
|
|
|
void sphore_init(SEMAPHORE *sem);
|
|
|
|
void sphore_wait(SEMAPHORE *sem);
|
|
|
|
void sphore_signal(SEMAPHORE *sem);
|
|
|
|
void sphore_destroy(SEMAPHORE *sem);
|
2017-08-31 08:59:12 +00:00
|
|
|
|
2020-04-12 17:56:11 +00:00
|
|
|
void set_new_tick(void);
|
2014-11-09 23:08:50 +00:00
|
|
|
|
2018-03-12 15:12:06 +00:00
|
|
|
/*
|
|
|
|
Function: time_get_impl
|
|
|
|
Fetches a sample from a high resolution timer.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Current value of the timer.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
To know how fast the timer is ticking, see <time_freq>.
|
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time_get_impl(void);
|
2018-03-12 15:12:06 +00:00
|
|
|
|
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>.
|
2018-03-12 15:12:06 +00:00
|
|
|
Uses <time_get_impl> to fetch the sample.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time_get(void);
|
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: 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
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time_freq(void);
|
2007-08-22 07:52:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: time_timestamp
|
2018-07-10 09:29:02 +00:00
|
|
|
Retrieves 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
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int time_timestamp(void);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2020-09-18 16:45:42 +00:00
|
|
|
/*
|
|
|
|
Function: time_houroftheday
|
|
|
|
Retrieves the hours since midnight (0..23)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The current hour of the day
|
|
|
|
*/
|
|
|
|
int time_houroftheday(void);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SEASON_SPRING = 0,
|
|
|
|
SEASON_SUMMER,
|
|
|
|
SEASON_AUTUMN,
|
2020-12-28 16:20:29 +00:00
|
|
|
SEASON_WINTER,
|
|
|
|
SEASON_NEWYEAR
|
2020-09-18 16:45:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: time_season
|
|
|
|
Retrieves the current season of the year.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
one of the SEASON_* enum literals
|
|
|
|
*/
|
|
|
|
int time_season(void);
|
|
|
|
|
2018-03-12 14:10:49 +00:00
|
|
|
/*
|
|
|
|
Function: time_get_microseconds
|
|
|
|
Fetches a sample from a high resolution timer and converts it in microseconds.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Current value of the timer in microseconds.
|
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time_get_microseconds(void);
|
2018-03-12 14:10:49 +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;
|
2015-02-07 22:15:58 +00:00
|
|
|
int web_ipv4sock;
|
2011-03-28 18:11:28 +00:00
|
|
|
} NETSOCKET;
|
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +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,
|
2015-02-07 22:15:58 +00:00
|
|
|
NETTYPE_WEBSOCKET_IPV4 = 8,
|
2020-09-26 19:41:58 +00:00
|
|
|
NETTYPE_ALL = NETTYPE_IPV4 | NETTYPE_IPV6 | NETTYPE_WEBSOCKET_IPV4
|
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;
|
|
|
|
|
2017-12-20 15:56:34 +00:00
|
|
|
#ifdef CONF_FAMILY_UNIX
|
|
|
|
typedef int UNIXSOCKET;
|
|
|
|
typedef struct sockaddr_un UNIXSOCKETADDR;
|
|
|
|
#endif
|
2008-08-05 21:37:33 +00:00
|
|
|
/*
|
|
|
|
Function: net_init
|
2018-07-10 09:29:02 +00:00
|
|
|
Initiates network functionality.
|
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.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int net_init(void);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
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
|
2018-02-04 15:00:47 +00:00
|
|
|
NETADDR struct with the received 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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - Address a is less than address b
|
2008-08-05 21:37:33 +00:00
|
|
|
0 - Address a is equal to address b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - Address a is greater than address b
|
2008-08-05 21:37:33 +00:00
|
|
|
*/
|
|
|
|
int net_addr_comp(const NETADDR *a, const NETADDR *b);
|
|
|
|
|
2018-10-07 22:59:07 +00:00
|
|
|
/*
|
2018-10-08 16:56:51 +00:00
|
|
|
Function: net_addr_comp_noport
|
|
|
|
Compares two network addresses ignoring port.
|
2018-10-07 22:59:07 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - Address to compare
|
|
|
|
b - Address to compare to.
|
|
|
|
|
|
|
|
Returns:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - Address a is less than address b
|
2018-10-07 22:59:07 +00:00
|
|
|
0 - Address a is equal to address b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - Address a is greater than address b
|
2018-10-07 22:59:07 +00:00
|
|
|
*/
|
2018-10-08 16:56:51 +00:00
|
|
|
int net_addr_comp_noport(const NETADDR *a, const NETADDR *b);
|
2018-10-07 22:59:07 +00:00
|
|
|
|
2008-08-05 21:37:33 +00:00
|
|
|
/*
|
|
|
|
Function: net_addr_str
|
2018-02-04 15:00:47 +00:00
|
|
|
Turns a network address into a representative 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
|
|
|
|
2018-07-25 14:06:00 +00:00
|
|
|
#define VLEN 128
|
|
|
|
#define PACKETSIZE 1400
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
#ifdef CONF_PLATFORM_LINUX
|
|
|
|
int pos;
|
|
|
|
int size;
|
|
|
|
struct mmsghdr msgs[VLEN];
|
|
|
|
struct iovec iovecs[VLEN];
|
2018-12-17 19:49:25 +00:00
|
|
|
char bufs[VLEN][PACKETSIZE];
|
2018-12-23 21:31:55 +00:00
|
|
|
char sockaddrs[VLEN][128];
|
2018-12-17 13:44:19 +00:00
|
|
|
#else
|
2018-12-17 13:53:52 +00:00
|
|
|
int dummy;
|
2018-07-25 14:06:00 +00:00
|
|
|
#endif
|
|
|
|
} MMSGS;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
void net_init_mmsgs(MMSGS *m);
|
2018-07-25 14:06:00 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: net_udp_recv
|
2018-07-10 09:29:02 +00:00
|
|
|
Receives a packet over an UDP socket.
|
2007-08-22 07:52:33 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to use.
|
2018-07-10 09:29:02 +00:00
|
|
|
addr - Pointer to an NETADDR that will receive the address.
|
2018-12-17 21:15:41 +00:00
|
|
|
buffer - Pointer to a buffer that can be used to receive the data.
|
2018-07-10 09:29:02 +00:00
|
|
|
maxsize - Maximum size to receive.
|
2018-12-17 21:15:41 +00:00
|
|
|
data - Will get set to the actual data, might be the passed buffer or an internal one
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2007-08-22 07:52:33 +00:00
|
|
|
Returns:
|
2018-02-04 15:00:47 +00:00
|
|
|
On success it returns the number of bytes received. Returns -1
|
2008-08-05 21:37:33 +00:00
|
|
|
on error.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *buffer, int maxsize, MMSGS *m, unsigned char **data);
|
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.
|
2018-02-04 15:00:47 +00:00
|
|
|
backlog - Size of the queue of incoming 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
|
|
|
|
2017-12-20 15:56:34 +00:00
|
|
|
#if defined(CONF_FAMILY_UNIX)
|
|
|
|
/* Group: Network Unix Sockets */
|
|
|
|
|
|
|
|
/*
|
2017-12-20 15:56:44 +00:00
|
|
|
Function: net_unix_create_unnamed
|
|
|
|
Creates an unnamed unix datagram socket.
|
2017-12-20 15:56:34 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
On success it returns a handle to the socket. On failure it returns -1.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
UNIXSOCKET net_unix_create_unnamed(void);
|
2017-12-20 15:56:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_unix_send
|
|
|
|
Sends data to a Unix socket.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to use.
|
|
|
|
addr - Where to send the packet.
|
|
|
|
data - Pointer to the packet data to send.
|
|
|
|
size - Size of the packet.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of bytes sent. Negative value on failure.
|
|
|
|
*/
|
|
|
|
int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_unix_set_addr
|
|
|
|
Sets the unixsocketaddress for a path to a socket file.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
addr - Pointer to the addressstruct to fill.
|
|
|
|
path - Path to the (named) unix socket.
|
|
|
|
*/
|
|
|
|
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
|
2017-12-20 15:56:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_unix_close
|
|
|
|
Closes a Unix socket.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
sock - Socket to close.
|
|
|
|
*/
|
|
|
|
void net_unix_close(UNIXSOCKET sock);
|
|
|
|
|
2017-12-20 15:56:34 +00:00
|
|
|
#endif
|
|
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2018-02-04 15:00:47 +00:00
|
|
|
- Guarantees that dst string will contain zero-termination.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
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:
|
2018-07-10 09:29:02 +00:00
|
|
|
dst - Pointer to a buffer that shall receive the string.
|
2008-07-06 11:21:21 +00:00
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2018-02-04 15:00:47 +00:00
|
|
|
- Guarantees that dst string will contain zero-termination.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
|
|
|
void str_copy(char *dst, const char *src, int dst_size);
|
2008-02-10 21:54:52 +00:00
|
|
|
|
2019-04-16 00:24:24 +00:00
|
|
|
/*
|
2020-08-02 11:45:20 +00:00
|
|
|
Function: str_utf8_truncate
|
|
|
|
Truncates a utf8 encoded string to a given length.
|
2019-04-16 00:24:24 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
dst - Pointer to a buffer that shall receive the string.
|
|
|
|
dst_size - Size of the buffer dst.
|
2019-04-16 06:10:02 +00:00
|
|
|
str - String to be truncated.
|
2020-08-02 11:45:20 +00:00
|
|
|
truncation_len - Maximum codepoints in the returned string.
|
2019-04-16 00:24:24 +00:00
|
|
|
|
|
|
|
Remarks:
|
2020-08-02 11:45:20 +00:00
|
|
|
- The strings are treated as utf8-encoded zero-terminated strings.
|
2019-04-16 00:24:24 +00:00
|
|
|
- Guarantees that dst string will contain zero-termination.
|
|
|
|
*/
|
2020-08-02 11:45:20 +00:00
|
|
|
void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len);
|
2019-04-16 00:24:24 +00:00
|
|
|
|
2020-09-03 12:08:26 +00:00
|
|
|
/*
|
|
|
|
Function: str_truncate
|
|
|
|
Truncates a string to a given length.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
dst - Pointer to a buffer that shall receive the string.
|
|
|
|
dst_size - Size of the buffer dst.
|
|
|
|
src - String to be truncated.
|
|
|
|
truncation_len - Maximum length of the returned string (not
|
|
|
|
counting the zero termination).
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
- Garantees that dst string will contain zero-termination.
|
|
|
|
*/
|
|
|
|
void str_truncate(char *dst, int dst_size, const char *src, int truncation_len);
|
|
|
|
|
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
|
2018-07-10 09:29:02 +00:00
|
|
|
Performs printf formatting into a buffer.
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Parameters:
|
2018-07-10 09:29:02 +00:00
|
|
|
buffer - Pointer to the buffer to receive the formatted string.
|
2008-07-06 11:21:21 +00:00
|
|
|
buffer_size - Size of the buffer.
|
2018-07-10 09:29:02 +00:00
|
|
|
format - printf formatting string.
|
|
|
|
... - Parameters for the formatting.
|
2008-01-29 21:39:41 +00:00
|
|
|
|
2013-07-21 02:52:23 +00:00
|
|
|
Returns:
|
2019-03-20 18:09:23 +00:00
|
|
|
Length of written string, even if it has been truncated
|
2013-07-21 02:52:23 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
Remarks:
|
2018-07-10 09:29:02 +00:00
|
|
|
- See the C manual for syntax for the printf formatting string.
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2018-02-04 15:00:47 +00:00
|
|
|
- Guarantees that dst string will contain zero-termination.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2017-07-26 01:58:00 +00:00
|
|
|
int str_format(char *buffer, int buffer_size, const char *format, ...)
|
2020-09-26 19:41:58 +00:00
|
|
|
GNUC_ATTRIBUTE((format(printf, 3, 4)));
|
2008-01-29 21:39:41 +00:00
|
|
|
|
2015-02-19 21:54:47 +00:00
|
|
|
/*
|
|
|
|
Function: str_trim_words
|
|
|
|
Trims specific number of words at the start of a string.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
str - String to trim the words from.
|
|
|
|
words - Count of words to trim.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Trimmed string
|
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2015-02-19 21:54:47 +00:00
|
|
|
*/
|
|
|
|
char *str_trim_words(char *str, int words);
|
|
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2010-08-12 13:22:07 +00:00
|
|
|
*/
|
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
2008-02-24 16:03:58 +00:00
|
|
|
void str_sanitize(char *str);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2017-09-28 13:59:30 +00:00
|
|
|
/*
|
|
|
|
Function: str_sanitize_filename
|
|
|
|
Replaces all invalid filename characters with whitespace.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
str - String to sanitize.
|
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2017-09-28 13:59:30 +00:00
|
|
|
*/
|
|
|
|
void str_sanitize_filename(char *str);
|
|
|
|
|
2013-09-04 14:44:04 +00:00
|
|
|
/*
|
|
|
|
Function: str_clean_whitespaces
|
|
|
|
Removes leading and trailing spaces and limits the use of multiple spaces.
|
|
|
|
Parameters:
|
|
|
|
str - String to clean up
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-termineted strings.
|
|
|
|
*/
|
|
|
|
void str_clean_whitespaces(char *str);
|
|
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2010-10-25 16:41:15 +00:00
|
|
|
*/
|
|
|
|
char *str_skip_to_whitespace(char *str);
|
|
|
|
|
2020-02-04 16:30:36 +00:00
|
|
|
/*
|
|
|
|
Function: str_skip_to_whitespace_const
|
|
|
|
See str_skip_to_whitespace.
|
|
|
|
*/
|
|
|
|
const char *str_skip_to_whitespace_const(const 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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2010-08-12 13:22:07 +00:00
|
|
|
*/
|
|
|
|
char *str_skip_whitespaces(char *str);
|
|
|
|
|
2020-02-04 16:30:36 +00:00
|
|
|
/*
|
|
|
|
Function: str_skip_whitespaces_const
|
|
|
|
See str_skip_whitespaces.
|
|
|
|
*/
|
|
|
|
const char *str_skip_whitespaces_const(const char *str);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_comp_nocase
|
2019-01-07 22:49:20 +00:00
|
|
|
Compares to strings case insensitively.
|
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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - String a is less than string b
|
2008-07-06 11:21:21 +00:00
|
|
|
0 - String a is equal to string b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - String a is greater than string b
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
Remarks:
|
2019-01-07 22:49:20 +00:00
|
|
|
- Only guaranteed to work with a-z/A-Z.
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
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
|
2019-01-07 22:49:20 +00:00
|
|
|
Compares up to num characters of two strings case insensitively.
|
2011-06-09 21:28:20 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
|
|
|
num - Maximum characters to compare
|
|
|
|
|
|
|
|
Returns:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - String a is less than string b
|
2011-06-09 21:28:20 +00:00
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater than string b
|
|
|
|
|
|
|
|
Remarks:
|
2019-01-07 22:49:20 +00:00
|
|
|
- Only guaranteed to work with a-z/A-Z.
|
|
|
|
(use str_utf8_comp_nocase_num for unicode support)
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2011-06-09 21:28:20 +00:00
|
|
|
*/
|
2019-01-07 22:49:20 +00:00
|
|
|
int str_comp_nocase_num(const char *a, const char *b, int num);
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
/*
|
2010-09-22 14:16:07 +00:00
|
|
|
Function: str_comp
|
2017-09-25 12:24:40 +00:00
|
|
|
Compares two 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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - String a is less than string b
|
2009-06-13 16:54:04 +00:00
|
|
|
0 - String a is equal to string b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - String a is greater than string b
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2009-06-13 16:54:04 +00:00
|
|
|
*/
|
|
|
|
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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - String a is less than string b
|
2010-05-29 07:25:38 +00:00
|
|
|
0 - String a is equal to string b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - String a is greater than string b
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2010-05-29 07:25:38 +00:00
|
|
|
*/
|
2019-01-07 22:49:20 +00:00
|
|
|
int str_comp_num(const char *a, const char *b, int num);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
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:
|
2019-01-07 22:49:20 +00:00
|
|
|
<0 - String a is less than string b
|
2010-09-28 22:53:53 +00:00
|
|
|
0 - String a is equal to string b
|
2018-10-08 16:55:18 +00:00
|
|
|
>0 - String a is greater than string b
|
2010-09-28 22:53:53 +00:00
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2010-09-28 22:53:53 +00:00
|
|
|
*/
|
|
|
|
int str_comp_filenames(const char *a, const char *b);
|
|
|
|
|
2018-07-25 08:23:07 +00:00
|
|
|
/*
|
|
|
|
Function: str_startswith
|
|
|
|
Checks whether the string begins with a certain prefix.
|
|
|
|
|
|
|
|
Parameter:
|
|
|
|
str - String to check.
|
|
|
|
prefix - Prefix to look for.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A pointer to the string str after the string prefix, or 0 if
|
|
|
|
the string prefix isn't a prefix of the string str.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
const char *str_startswith(const char *str, const char *prefix);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_endswith
|
|
|
|
Checks whether the string ends with a certain suffix.
|
|
|
|
|
|
|
|
Parameter:
|
|
|
|
str - String to check.
|
|
|
|
suffix - Suffix to look for.
|
|
|
|
|
|
|
|
Returns:
|
2018-07-26 12:04:44 +00:00
|
|
|
A pointer to the beginning of the suffix in the string str, or
|
|
|
|
0 if the string suffix isn't a suffix of the string str.
|
2018-07-25 08:23:07 +00:00
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
2018-07-26 12:04:44 +00:00
|
|
|
const char *str_endswith(const char *str, const char *suffix);
|
2018-07-25 08:23:07 +00:00
|
|
|
|
2018-03-06 17:41:18 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_dist
|
|
|
|
Computes the edit distance between two strings.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - First string for the edit distance.
|
|
|
|
b - Second string for the edit distance.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The edit distance between the both strings.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
int str_utf8_dist(const char *a, const char *b);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_dist_buffer
|
|
|
|
Computes the edit distance between two strings, allows buffers
|
|
|
|
to be passed in.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - First string for the edit distance.
|
|
|
|
b - Second string for the edit distance.
|
|
|
|
buf - Buffer for the function.
|
|
|
|
buf_len - Length of the buffer, must be at least as long as
|
|
|
|
twice the length of both strings combined plus two.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The edit distance between the both strings.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf32_dist_buffer
|
|
|
|
Computes the edit distance between two strings, allows buffers
|
|
|
|
to be passed in.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - First string for the edit distance.
|
|
|
|
a_len - Length of the first string.
|
|
|
|
b - Second string for the edit distance.
|
|
|
|
b_len - Length of the second string.
|
|
|
|
buf - Buffer for the function.
|
|
|
|
buf_len - Length of the buffer, must be at least as long as
|
|
|
|
the length of both strings combined plus two.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The edit distance between the both strings.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_find_nocase
|
2019-01-07 22:49:20 +00:00
|
|
|
Finds a string inside another string case insensitively.
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
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.
|
2019-04-16 00:24:24 +00:00
|
|
|
Returns NULL if needle could not be found.
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
Remarks:
|
2019-01-07 22:49:20 +00:00
|
|
|
- Only guaranteed to work with a-z/A-Z.
|
|
|
|
(use str_utf8_find_nocase for unicode support)
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
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.
|
2019-04-16 00:24:24 +00:00
|
|
|
Returns NULL if needle could not be found.
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
Remarks:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The strings are treated as zero-terminated strings.
|
2009-06-13 16:54:04 +00:00
|
|
|
*/
|
|
|
|
const char *str_find(const char *haystack, const char *needle);
|
2008-07-06 11:21:21 +00:00
|
|
|
|
2019-04-16 00:24:24 +00:00
|
|
|
/*
|
|
|
|
Function: str_rchr
|
|
|
|
Finds the last occurance of a character
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
haystack - String to search in
|
|
|
|
needle - Character to search for
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A pointer into haystack where the needle was found.
|
|
|
|
Returns NULL if needle could not be found.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
const char *str_rchr(const char *haystack, char needle);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
Function: str_hex
|
2018-08-19 10:12:11 +00:00
|
|
|
Takes a datablock and generates a hex string of it, with spaces
|
|
|
|
between bytes.
|
2008-07-06 11:21:21 +00:00
|
|
|
|
|
|
|
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:
|
2018-07-10 09:29:02 +00:00
|
|
|
- The destination buffer will be zero-terminated
|
2008-07-06 11:21:21 +00:00
|
|
|
*/
|
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
|
|
|
|
2017-03-02 15:16:29 +00:00
|
|
|
/*
|
|
|
|
Function: str_hex_decode
|
2018-08-19 10:12:11 +00:00
|
|
|
Takes a hex string *without spaces between bytes* and returns a
|
|
|
|
byte array.
|
2017-03-02 15:16:29 +00:00
|
|
|
|
2018-03-06 17:41:18 +00:00
|
|
|
Parameters:
|
|
|
|
dst - Buffer for the byte array
|
|
|
|
dst_size - size of the buffer
|
|
|
|
data - String to decode
|
2017-03-04 20:06:07 +00:00
|
|
|
|
2018-03-06 17:41:18 +00:00
|
|
|
Returns:
|
|
|
|
2 - String doesn't exactly fit the buffer
|
|
|
|
1 - Invalid character in string
|
|
|
|
0 - Success
|
2017-03-04 20:06:07 +00:00
|
|
|
|
2018-03-06 17:41:18 +00:00
|
|
|
Remarks:
|
|
|
|
- The contents of the buffer is only valid on success
|
2017-03-02 15:16:29 +00:00
|
|
|
*/
|
2018-08-19 10:12:11 +00:00
|
|
|
int str_hex_decode(void *dst, int dst_size, const char *src);
|
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);
|
2019-07-14 13:42:16 +00:00
|
|
|
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
|
2020-09-26 19:41:58 +00:00
|
|
|
GNUC_ATTRIBUTE((format(strftime, 3, 0)));
|
2017-07-26 01:58:00 +00:00
|
|
|
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
|
2020-09-26 19:41:58 +00:00
|
|
|
GNUC_ATTRIBUTE((format(strftime, 4, 0)));
|
2010-12-07 23:26:55 +00:00
|
|
|
|
2017-08-04 20:38:22 +00:00
|
|
|
#define FORMAT_TIME "%H:%M:%S"
|
|
|
|
#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
|
|
|
|
#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
|
|
|
|
|
2020-10-18 20:44:02 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TIME_DAYS,
|
|
|
|
TIME_HOURS,
|
|
|
|
TIME_MINS,
|
|
|
|
TIME_HOURS_CENTISECS,
|
|
|
|
TIME_MINS_CENTISECS,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_times
|
|
|
|
Formats a time string.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
centisecs - Time in centiseconds, minimum value clamped to 0
|
|
|
|
format - Format of the time string, see enum above, for example TIME_DAYS
|
|
|
|
buffer - Pointer to a buffer that shall receive the time stamp string.
|
|
|
|
buffer_size - Size of the buffer.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of bytes written, -1 on invalid format or buffer_size <= 0
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Guarantees that buffer string will contain zero-termination, assuming
|
|
|
|
buffer_size > 0.
|
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int str_time(int64_t centisecs, int format, char *buffer, int buffer_size);
|
2020-10-18 20:44:02 +00:00
|
|
|
int str_time_float(float secs, int format, char *buffer, int buffer_size);
|
|
|
|
|
2017-07-08 09:03:51 +00:00
|
|
|
/*
|
|
|
|
Function: str_escape
|
|
|
|
Escapes \ and " characters in a string.
|
|
|
|
|
|
|
|
Parameters:
|
2017-07-08 11:06:03 +00:00
|
|
|
dst - Destination array pointer, gets increased, will point to
|
|
|
|
the terminating null.
|
2017-07-08 09:03:51 +00:00
|
|
|
src - Source array
|
|
|
|
end - End of destination array
|
|
|
|
*/
|
|
|
|
void str_escape(char **dst, const char *src, const char *end);
|
|
|
|
|
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);
|
2015-08-27 12:57:56 +00:00
|
|
|
typedef int (*FS_LISTDIR_INFO_CALLBACK)(const char *name, time_t date, 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);
|
2015-08-27 12:57:56 +00:00
|
|
|
int fs_listdir_info(const char *dir, FS_LISTDIR_INFO_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);
|
|
|
|
|
2021-04-21 10:52:27 +00:00
|
|
|
/*
|
|
|
|
Function: fs_removedir
|
|
|
|
Removes a directory
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
path - Directory to remove
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns 0 on success. Negative value on failure.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
Cannot remove a non-empty directory.
|
|
|
|
*/
|
|
|
|
int fs_removedir(const char *path);
|
|
|
|
|
2016-05-01 12:20:55 +00:00
|
|
|
/*
|
|
|
|
Function: fs_makedir_rec_for
|
|
|
|
Recursively create directories for a file
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
path - File for which to create directories
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns 0 on success. Negative value on failure.
|
|
|
|
*/
|
|
|
|
int fs_makedir_rec_for(const char *path);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
/*
|
|
|
|
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
|
2021-02-12 12:40:29 +00:00
|
|
|
- Returns ~/Library/Applications Support/appname on macOS
|
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);
|
|
|
|
|
2015-08-22 15:57:58 +00:00
|
|
|
/*
|
|
|
|
Function: fs_getmtime
|
|
|
|
Gets the modification time of a file
|
|
|
|
*/
|
|
|
|
time_t fs_getmtime(const char *path);
|
|
|
|
|
2008-10-01 17:16:22 +00:00
|
|
|
/*
|
|
|
|
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:
|
2018-07-25 06:59:29 +00:00
|
|
|
- The string is treated as zero-terminated 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.
|
2021-04-21 10:52:27 +00:00
|
|
|
- Returns an error if the path specifies a directory name.
|
2010-12-07 23:13:59 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int net_errno(void);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: net_would_block
|
|
|
|
|
|
|
|
DOCTODO: serp
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int net_would_block(void);
|
2008-08-05 21:37:33 +00:00
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
int net_socket_read_wait(NETSOCKET sock, int time);
|
|
|
|
|
2020-06-19 15:04:35 +00:00
|
|
|
/*
|
|
|
|
Function: open_link
|
|
|
|
Opens a link in the browser.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
link - The link to open in a browser.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns 1 on success, 0 on failure.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
This may not be called with untrusted input or it'll result in arbitrary code execution.
|
|
|
|
*/
|
|
|
|
int open_link(const char *link);
|
|
|
|
|
2008-07-06 11:21:21 +00:00
|
|
|
void swap_endian(void *data, unsigned elem_size, unsigned num);
|
|
|
|
|
2017-10-10 01:33:54 +00:00
|
|
|
typedef void (*DBG_LOGGER)(const char *line, void *user);
|
2017-10-13 00:25:50 +00:00
|
|
|
typedef void (*DBG_LOGGER_FINISH)(void *user);
|
|
|
|
void dbg_logger(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, void *user);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-04-12 17:56:11 +00:00
|
|
|
void dbg_logger_stdout(void);
|
|
|
|
void dbg_logger_debugger(void);
|
2008-03-10 00:48:45 +00:00
|
|
|
void dbg_logger_file(const char *filename);
|
|
|
|
|
2008-04-05 14:50:43 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int sent_packets;
|
|
|
|
int sent_bytes;
|
|
|
|
int recv_packets;
|
|
|
|
int recv_bytes;
|
|
|
|
} NETSTATS;
|
|
|
|
|
|
|
|
void net_stats(NETSTATS *stats);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int str_toint(const char *str);
|
2015-08-20 10:51:30 +00:00
|
|
|
int str_toint_base(const char *str, int base);
|
2019-05-15 16:11:22 +00:00
|
|
|
unsigned long str_toulong_base(const char *str, int base);
|
2010-05-29 07:25:38 +00:00
|
|
|
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);
|
2019-02-27 19:24:31 +00:00
|
|
|
int str_isallnum(const char *str);
|
2009-06-15 13:01:04 +00:00
|
|
|
unsigned str_quickhash(const char *str);
|
2008-11-08 08:27:11 +00:00
|
|
|
|
2018-03-06 17:41:18 +00:00
|
|
|
struct SKELETON;
|
|
|
|
void str_utf8_skeleton_begin(struct SKELETON *skel, const char *str);
|
|
|
|
int str_utf8_skeleton_next(struct SKELETON *skel);
|
|
|
|
int str_utf8_to_skeleton(const char *str, int *buf, int buf_len);
|
|
|
|
|
2016-10-30 11:25:49 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_comp_confusable
|
|
|
|
Compares two strings for visual appearance.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
0 if the strings are confusable.
|
|
|
|
!=0 otherwise.
|
|
|
|
*/
|
|
|
|
int str_utf8_comp_confusable(const char *a, const char *b);
|
2014-11-24 15:22:00 +00:00
|
|
|
|
2019-01-07 22:49:20 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_tolower
|
|
|
|
Converts the given Unicode codepoint to lowercase (locale insensitive).
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
code - Unicode codepoint to convert.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Lowercase codepoint
|
|
|
|
*/
|
|
|
|
int str_utf8_tolower(int code);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_comp_nocase
|
|
|
|
Compares two utf8 strings case insensitively.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
<0 - String a is less than string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater than string b
|
|
|
|
*/
|
|
|
|
int str_utf8_comp_nocase(const char *a, const char *b);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_comp_nocase_num
|
|
|
|
Compares up to num bytes of two utf8 strings case insensitively.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
a - String to compare.
|
|
|
|
b - String to compare.
|
2019-02-11 16:11:33 +00:00
|
|
|
num - Maximum bytes to compare
|
2019-01-07 22:49:20 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
<0 - String a is less than string b
|
|
|
|
0 - String a is equal to string b
|
|
|
|
>0 - String a is greater than string b
|
|
|
|
*/
|
|
|
|
int str_utf8_comp_nocase_num(const char *a, const char *b, int num);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function: str_utf8_find_nocase
|
|
|
|
Finds a utf8 string inside another utf8 string case insensitively.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
haystack - String to search in
|
|
|
|
needle - String to search for
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A pointer into haystack where the needle was found.
|
2019-04-16 00:24:24 +00:00
|
|
|
Returns NULL if needle could not be found.
|
2019-01-07 22:49:20 +00:00
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
*/
|
|
|
|
const char *str_utf8_find_nocase(const char *haystack, const char *needle);
|
|
|
|
|
2018-03-14 01:27:15 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_isspace
|
|
|
|
Checks whether the given Unicode codepoint renders as space.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
code - Unicode codepoint to check.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
0 if the codepoint does not render as space, != 0 if it does.
|
|
|
|
*/
|
2014-11-08 19:14:12 +00:00
|
|
|
int str_utf8_isspace(int code);
|
|
|
|
|
2015-07-11 17:26:57 +00:00
|
|
|
int str_utf8_isstart(char c);
|
|
|
|
|
2018-03-14 01:27:15 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_skip_whitespaces
|
|
|
|
Skips leading characters that render as spaces.
|
|
|
|
|
|
|
|
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-terminated strings.
|
|
|
|
*/
|
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
|
|
|
|
2018-03-14 01:27:15 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_trim_right
|
|
|
|
Removes trailing characters that render as spaces by modifying
|
|
|
|
the string in-place.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
str - Pointer to the string.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
- The string is modified in-place.
|
|
|
|
*/
|
|
|
|
void str_utf8_trim_right(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
|
2015-06-30 19:09:43 +00:00
|
|
|
Decodes a utf8 codepoint
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-06-13 08:22:37 +00:00
|
|
|
Parameters:
|
2015-06-30 19:09:43 +00:00
|
|
|
ptr - Pointer to a 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:
|
2015-06-30 19:09:43 +00:00
|
|
|
The Unicode codepoint. -1 for invalid input and 0 for end of string.
|
2009-06-13 08:22:37 +00:00
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- This function will also move the pointer forward.
|
2018-02-04 15:00:47 +00:00
|
|
|
- You may call this function again after an error occurred.
|
2009-06-13 08:22:37 +00:00
|
|
|
*/
|
|
|
|
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:
|
2015-06-30 19:09:43 +00:00
|
|
|
ptr - Pointer to a buffer that should receive 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);
|
|
|
|
|
2018-12-07 22:52:33 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf16le_encode
|
|
|
|
Encode an utf8 character
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
ptr - Pointer to a buffer that should receive the data. Should be able to hold at least 4 bytes.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of bytes put into the buffer.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- Does not do zero termination of the string.
|
|
|
|
*/
|
|
|
|
int str_utf16le_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);
|
|
|
|
|
2020-09-06 19:54:57 +00:00
|
|
|
/*
|
|
|
|
Function: str_utf8_copy
|
|
|
|
Copies a utf8 string to a buffer.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
dst - Pointer to a buffer that shall receive the string.
|
|
|
|
src - utf8 string to be copied.
|
|
|
|
dst_size - Size of the buffer dst.
|
|
|
|
|
|
|
|
Remarks:
|
|
|
|
- The strings are treated as zero-terminated strings.
|
|
|
|
- Guarantees that dst string will contain zero-termination.
|
2020-09-06 19:58:26 +00:00
|
|
|
- Guarantees that dst always contains a valid utf8 string.
|
2020-09-06 19:54:57 +00:00
|
|
|
*/
|
|
|
|
void str_utf8_copy(char *dst, const char *src, int dst_size);
|
|
|
|
|
2019-03-05 09:46:29 +00:00
|
|
|
/*
|
2019-03-11 11:39:54 +00:00
|
|
|
Function: str_next_token
|
|
|
|
Writes the next token after str into buf, returns the rest of the string.
|
2019-03-05 09:46:29 +00:00
|
|
|
Parameters:
|
|
|
|
str - Pointer to string.
|
|
|
|
delim - Delimiter for tokenization.
|
2019-03-11 11:39:54 +00:00
|
|
|
buffer - Buffer to store token in.
|
|
|
|
buffer_size - Size of the buffer.
|
2019-03-05 09:46:29 +00:00
|
|
|
Returns:
|
2019-03-11 11:39:54 +00:00
|
|
|
Pointer to rest of the string.
|
2019-03-05 09:46:29 +00:00
|
|
|
Remarks:
|
|
|
|
- The token is always null-terminated.
|
|
|
|
*/
|
2019-03-11 11:39:54 +00:00
|
|
|
const char *str_next_token(const char *str, const char *delim, char *buffer, int buffer_size);
|
2019-03-05 09:46:29 +00:00
|
|
|
|
2019-02-06 12:30:47 +00:00
|
|
|
/*
|
|
|
|
Function: str_in_list
|
|
|
|
Checks if needle is in list delimited by delim
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
list - List
|
|
|
|
delim - List delimiter.
|
|
|
|
needle - Item that is being looked for.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
1 - Item is in list.
|
|
|
|
0 - Item isn't in list.
|
|
|
|
*/
|
|
|
|
int str_in_list(const char *list, const char *delim, const char *needle);
|
|
|
|
|
2020-09-03 12:08:26 +00:00
|
|
|
/*
|
|
|
|
Function: pid
|
|
|
|
Returns the pid of the current process.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
pid of the current process
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int pid(void);
|
2014-08-22 12:18:16 +00:00
|
|
|
|
2020-09-05 22:38:35 +00:00
|
|
|
#if defined(CONF_FAMILY_WINDOWS)
|
|
|
|
typedef void *PROCESS;
|
|
|
|
#else
|
|
|
|
typedef pid_t PROCESS;
|
|
|
|
#endif
|
|
|
|
|
2015-04-18 12:53:11 +00:00
|
|
|
/*
|
|
|
|
Function: shell_execute
|
|
|
|
Executes a given file.
|
2020-09-03 12:08:26 +00:00
|
|
|
|
|
|
|
Returns:
|
2020-09-05 22:38:35 +00:00
|
|
|
handle/pid of the new process
|
2015-04-18 12:53:11 +00:00
|
|
|
*/
|
2020-09-05 22:38:35 +00:00
|
|
|
PROCESS shell_execute(const char *file);
|
2020-09-03 12:08:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function: kill_process
|
|
|
|
Sends kill signal to a process.
|
|
|
|
|
|
|
|
Parameters:
|
2020-09-05 22:38:35 +00:00
|
|
|
process - handle/pid of the process
|
2020-09-03 12:08:26 +00:00
|
|
|
|
|
|
|
Returns:
|
2020-09-05 22:38:35 +00:00
|
|
|
0 - Error
|
|
|
|
1 - Success
|
2020-09-03 12:08:26 +00:00
|
|
|
*/
|
2020-09-05 22:38:35 +00:00
|
|
|
int kill_process(PROCESS process);
|
2014-12-31 14:07:44 +00:00
|
|
|
|
2015-04-18 12:53:11 +00:00
|
|
|
/*
|
2017-11-23 02:10:15 +00:00
|
|
|
Function: os_is_winxp_or_lower
|
|
|
|
Checks whether the program runs on Windows XP or lower.
|
2015-04-18 12:53:11 +00:00
|
|
|
|
|
|
|
Returns:
|
2017-11-23 02:10:15 +00:00
|
|
|
1 - Windows XP or lower.
|
|
|
|
0 - Higher Windows version, Linux, macOS, etc.
|
2015-04-18 12:53:11 +00:00
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int os_is_winxp_or_lower(void);
|
2015-04-18 12:53:11 +00:00
|
|
|
|
2016-10-01 21:04:16 +00:00
|
|
|
/*
|
|
|
|
Function: generate_password
|
|
|
|
Generates a null-terminated password of length `2 *
|
|
|
|
random_length`.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
buffer - Pointer to the start of the output buffer.
|
|
|
|
length - Length of the buffer.
|
|
|
|
random - Pointer to a randomly-initialized array of shorts.
|
|
|
|
random_length - Length of the short array.
|
|
|
|
*/
|
|
|
|
void generate_password(char *buffer, unsigned length, unsigned short *random, unsigned random_length);
|
|
|
|
|
2015-03-05 23:53:59 +00:00
|
|
|
/*
|
|
|
|
Function: secure_random_init
|
|
|
|
Initializes the secure random module.
|
|
|
|
You *MUST* check the return value of this function.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
0 - Initialization succeeded.
|
|
|
|
1 - Initialization failed.
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int secure_random_init(void);
|
2015-03-05 23:53:59 +00:00
|
|
|
|
2016-10-01 21:04:16 +00:00
|
|
|
/*
|
|
|
|
Function: secure_random_password
|
|
|
|
Fills the buffer with the specified amount of random password
|
|
|
|
characters.
|
|
|
|
|
|
|
|
The desired password length must be greater or equal to 6, even
|
|
|
|
and smaller or equal to 128.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
buffer - Pointer to the start of the buffer.
|
|
|
|
length - Length of the buffer.
|
|
|
|
pw_length - Length of the desired password.
|
|
|
|
*/
|
|
|
|
void secure_random_password(char *buffer, unsigned length, unsigned pw_length);
|
|
|
|
|
2015-03-05 23:53:59 +00:00
|
|
|
/*
|
|
|
|
Function: secure_random_fill
|
|
|
|
Fills the buffer with the specified amount of random bytes.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
buffer - Pointer to the start of the buffer.
|
|
|
|
length - Length of the buffer.
|
|
|
|
*/
|
2016-10-01 21:04:16 +00:00
|
|
|
void secure_random_fill(void *bytes, unsigned length);
|
2015-03-05 23:53:59 +00:00
|
|
|
|
2016-01-02 14:37:44 +00:00
|
|
|
/*
|
|
|
|
Function: secure_rand
|
|
|
|
Returns random int (replacement for rand()).
|
|
|
|
*/
|
2020-04-12 17:56:11 +00:00
|
|
|
int secure_rand(void);
|
2016-01-02 14:37:44 +00:00
|
|
|
|
2021-03-13 15:52:35 +00:00
|
|
|
/*
|
|
|
|
Function: secure_rand_below
|
|
|
|
Returns a random nonnegative integer below the given number,
|
|
|
|
with a uniform distribution.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
below - Upper limit (exclusive) of integers to return.
|
|
|
|
*/
|
|
|
|
int secure_rand_below(int below);
|
|
|
|
|
2021-06-15 01:24:23 +00:00
|
|
|
#if defined(__cplusplus)
|
2007-08-22 07:52:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|