DDraceNetwork Docs
system.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
4/*
5 Title: OS Abstraction
6*/
7
8#ifndef BASE_SYSTEM_H
9#define BASE_SYSTEM_H
10
11#include "detect.h"
12#include "types.h"
13
14#ifndef __USE_GNU
15#define __USE_GNU
16#endif
17
18#include <chrono>
19#include <cinttypes>
20#include <cstdarg>
21#include <cstdint>
22#include <cstring>
23#include <ctime>
24#include <functional>
25#include <mutex>
26#include <optional>
27#include <string>
28
29#ifdef __MINGW32__
30#undef PRId64
31#undef PRIu64
32#undef PRIX64
33#define PRId64 "I64d"
34#define PRIu64 "I64u"
35#define PRIX64 "I64X"
36#define PRIzu "Iu"
37#else
38#define PRIzu "zu"
39#endif
40
41#ifdef CONF_FAMILY_UNIX
42#include <sys/un.h>
43#endif
44
45#ifdef CONF_PLATFORM_LINUX
46#include <netinet/in.h>
47#include <sys/socket.h>
48#endif
49
50#if __cplusplus >= 201703L
51#define MAYBE_UNUSED [[maybe_unused]]
52#elif defined(__GNUC__)
53#define MAYBE_UNUSED __attribute__((unused))
54#else
55#define MAYBE_UNUSED
56#endif
57
76#define dbg_assert(test, msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
77void dbg_assert_imp(const char *filename, int line, bool test, const char *msg);
78
79#ifdef __clang_analyzer__
80#include <cassert>
81#undef dbg_assert
82#define dbg_assert(test, msg) assert(test)
83#endif
84
85#ifdef __GNUC__
86#define GNUC_ATTRIBUTE(x) __attribute__(x)
87#else
88#define GNUC_ATTRIBUTE(x)
89#endif
90
101
110#if defined(__cplusplus)
111[[noreturn]]
112#endif
113void
114dbg_break();
115
116typedef std::function<void(const char *message)> DBG_ASSERT_HANDLER;
118
131void dbg_msg(const char *sys, const char *fmt, ...)
132 GNUC_ATTRIBUTE((format(printf, 2, 3)));
133
152void mem_copy(void *dest, const void *source, size_t size);
153
167void mem_move(void *dest, const void *source, size_t size);
168
177template<typename T>
178inline void mem_zero(T *block, size_t size)
179{
180 static_assert((std::is_trivially_constructible<T>::value && std::is_trivially_destructible<T>::value) || std::is_fundamental<T>::value);
181 memset(block, 0, size);
182}
183
197int mem_comp(const void *a, const void *b, size_t size);
198
209bool mem_has_null(const void *block, size_t size);
210
220enum
221{
240};
241
246{
265};
266
279IOHANDLE io_open(const char *filename, int flags);
280
292unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
293
310bool io_read_all(IOHANDLE io, void **result, unsigned *result_len);
311
328char *io_read_all_str(IOHANDLE io);
329
340int io_skip(IOHANDLE io, int64_t size);
341
353int io_seek(IOHANDLE io, int64_t offset, ESeekOrigin origin);
354
364int64_t io_tell(IOHANDLE io);
365
375int64_t io_length(IOHANDLE io);
376
388unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
389
400
410int io_close(IOHANDLE io);
411
421int io_flush(IOHANDLE io);
422
432int io_sync(IOHANDLE io);
433
443int io_error(IOHANDLE io);
444
455
466
477
486
492typedef struct ASYNCIO ASYNCIO;
493
504
513void aio_lock(ASYNCIO *aio);
514
523void aio_unlock(ASYNCIO *aio);
524
534void aio_write(ASYNCIO *aio, const void *buffer, unsigned size);
535
543void aio_write_newline(ASYNCIO *aio);
544
555void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size);
556
566
581int aio_error(ASYNCIO *aio);
582
590void aio_close(ASYNCIO *aio);
591
599void aio_wait(ASYNCIO *aio);
600
608void aio_free(ASYNCIO *aio);
609
629void *thread_init(void (*threadfunc)(void *), void *user, const char *name);
630
638void thread_wait(void *thread);
639
645void thread_yield();
646
656void thread_detach(void *thread);
657
667void thread_init_and_detach(void (*threadfunc)(void *), void *user, const char *name);
668
674#if defined(CONF_FAMILY_WINDOWS)
675typedef void *SEMAPHORE;
676#elif defined(CONF_PLATFORM_MACOS)
677#include <semaphore.h>
678typedef sem_t *SEMAPHORE;
679#elif defined(CONF_FAMILY_UNIX)
680#include <semaphore.h>
681typedef sem_t SEMAPHORE;
682#else
683#error not implemented on this platform
684#endif
685
689void sphore_init(SEMAPHORE *sem);
693void sphore_wait(SEMAPHORE *sem);
697void sphore_signal(SEMAPHORE *sem);
701void sphore_destroy(SEMAPHORE *sem);
702
712void set_new_tick();
713
725int64_t time_get_impl();
726
739int64_t time_get();
740
746int64_t time_freq();
747
755int64_t time_timestamp();
756
765
770{
780
791
796extern const NETADDR NETADDR_ZEROED;
797
802#ifdef CONF_FAMILY_UNIX
806typedef int UNIXSOCKET;
810typedef struct sockaddr_un UNIXSOCKETADDR;
811#endif
812
820void net_init();
821
822/*
823 Function: net_host_lookup
824 Does a hostname lookup by name and fills out the passed
825 NETADDR struct with the received details.
826
827 Returns:
828 0 on success.
829*/
830int net_host_lookup(const char *hostname, NETADDR *addr, int types);
831
844int net_addr_comp(const NETADDR *a, const NETADDR *b);
845
858int net_addr_comp_noport(const NETADDR *a, const NETADDR *b);
859
874bool net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port);
875
899int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size);
900
909int net_addr_from_str(NETADDR *addr, const char *string);
910
916/*
917 Function: net_socket_type
918 Determine a socket's type.
919
920 Parameters:
921 sock - Socket whose type should be determined.
922
923 Returns:
924 The socket type, a bitset of `NETTYPE_IPV4`, `NETTYPE_IPV6` and
925 `NETTYPE_WEBSOCKET_IPV4`.
926*/
927int net_socket_type(NETSOCKET sock);
928
929/*
930 Function: net_udp_create
931 Creates a UDP socket and binds it to a port.
932
933 Parameters:
934 bindaddr - Address to bind the socket to.
935
936 Returns:
937 On success it returns an handle to the socket. On failure it
938 returns NETSOCKET_INVALID.
939*/
941
955int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
956
957/*
958 Function: net_udp_recv
959 Receives a packet over an UDP socket.
960
961 Parameters:
962 sock - Socket to use.
963 addr - Pointer to an NETADDR that will receive the address.
964 data - Received data. Will be invalidated when this function is
965 called again.
966
967 Returns:
968 On success it returns the number of bytes received. Returns -1
969 on error.
970*/
971int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data);
972
982int net_udp_close(NETSOCKET sock);
983
999
1010int net_tcp_listen(NETSOCKET sock, int backlog);
1011
1023int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
1024
1036int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
1037
1049int net_tcp_send(NETSOCKET sock, const void *data, int size);
1050
1064int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
1065
1075int net_tcp_close(NETSOCKET sock);
1076
1077#if defined(CONF_FAMILY_UNIX)
1091
1104int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
1105
1114void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
1115
1123void net_unix_close(UNIXSOCKET sock);
1124
1125#elif defined(CONF_FAMILY_WINDOWS)
1126
1134std::string windows_format_system_message(unsigned long error);
1135
1136#endif
1137
1156void str_append(char *dst, const char *src, int dst_size);
1157
1169template<int N>
1170void str_append(char (&dst)[N], const char *src)
1171{
1172 str_append(dst, src, N);
1173}
1174
1189int str_copy(char *dst, const char *src, int dst_size);
1190
1202template<int N>
1203void str_copy(char (&dst)[N], const char *src)
1204{
1205 str_copy(dst, src, N);
1206}
1207
1221void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1222
1237void str_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1238
1248int str_length(const char *str);
1249
1266int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
1267 GNUC_ATTRIBUTE((format(printf, 3, 0)));
1268
1285int str_format(char *buffer, int buffer_size, const char *format, ...)
1286 GNUC_ATTRIBUTE((format(printf, 3, 4)));
1287
1288#if !defined(CONF_DEBUG)
1289int str_format_int(char *buffer, size_t buffer_size, int value);
1290
1291template<typename... Args>
1292int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
1293{
1294 static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
1295 return str_format(buffer, buffer_size, format, args...);
1296}
1297
1298template<>
1299inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
1300{
1301 if(strcmp(format, "%d") == 0)
1302 {
1303 return str_format_int(buffer, buffer_size, val);
1304 }
1305 else
1306 {
1307 return str_format(buffer, buffer_size, format, val);
1308 }
1309}
1310
1311#define str_format str_format_opt
1312#endif
1313
1327const char *str_trim_words(const char *str, int words);
1328
1340bool str_has_cc(const char *str);
1341
1351void str_sanitize_cc(char *str);
1352
1363void str_sanitize(char *str);
1364
1372void str_sanitize_filename(char *str);
1373
1383void str_clean_whitespaces(char *str);
1384
1398char *str_skip_to_whitespace(char *str);
1399
1404const char *str_skip_to_whitespace_const(const char *str);
1405
1419char *str_skip_whitespaces(char *str);
1420
1425const char *str_skip_whitespaces_const(const char *str);
1426
1442int str_comp_nocase(const char *a, const char *b);
1443
1461int str_comp_nocase_num(const char *a, const char *b, int num);
1462
1477int str_comp(const char *a, const char *b);
1478
1494int str_comp_num(const char *a, const char *b, int num);
1495
1510int str_comp_filenames(const char *a, const char *b);
1511
1512/*
1513 Function: str_startswith_nocase
1514 Checks case insensitive whether the string begins with a certain prefix.
1515
1516 Parameter:
1517 str - String to check.
1518 prefix - Prefix to look for.
1519
1520 Returns:
1521 A pointer to the string str after the string prefix, or 0 if
1522 the string prefix isn't a prefix of the string str.
1523
1524 Remarks:
1525 - The strings are treated as zero-terminated strings.
1526*/
1527const char *str_startswith_nocase(const char *str, const char *prefix);
1528
1542const char *str_startswith(const char *str, const char *prefix);
1543
1544/*
1545 Function: str_endswith_nocase
1546 Checks case insensitive whether the string ends with a certain suffix.
1547
1548 Parameter:
1549 str - String to check.
1550 suffix - Suffix to look for.
1551
1552 Returns:
1553 A pointer to the beginning of the suffix in the string str, or
1554 0 if the string suffix isn't a suffix of the string str.
1555
1556 Remarks:
1557 - The strings are treated as zero-terminated strings.
1558*/
1559const char *str_endswith_nocase(const char *str, const char *suffix);
1560
1561/*
1562 Function: str_endswith
1563 Checks case sensitive whether the string ends with a certain suffix.
1564
1565 Parameter:
1566 str - String to check.
1567 suffix - Suffix to look for.
1568
1569 Returns:
1570 A pointer to the beginning of the suffix in the string str, or
1571 0 if the string suffix isn't a suffix of the string str.
1572
1573 Remarks:
1574 - The strings are treated as zero-terminated strings.
1575*/
1576const char *str_endswith(const char *str, const char *suffix);
1577
1588int str_utf8_dist(const char *a, const char *b);
1589
1606int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len);
1607
1608/*
1609 Function: str_utf32_dist_buffer
1610 Computes the edit distance between two strings, allows buffers
1611 to be passed in.
1612
1613 Parameters:
1614 a - First string for the edit distance.
1615 a_len - Length of the first string.
1616 b - Second string for the edit distance.
1617 b_len - Length of the second string.
1618 buf - Buffer for the function.
1619 buf_len - Length of the buffer, must be at least as long as
1620 the length of both strings combined plus two.
1621
1622 Returns:
1623 The edit distance between the both strings.
1624
1625 Remarks:
1626 - The strings are treated as zero-terminated strings.
1627*/
1628int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len);
1629
1630/*
1631 Function: str_find_nocase
1632 Finds a string inside another string case insensitively.
1633
1634 Parameters:
1635 haystack - String to search in
1636 needle - String to search for
1637
1638 Returns:
1639 A pointer into haystack where the needle was found.
1640 Returns NULL if needle could not be found.
1641
1642 Remarks:
1643 - Only guaranteed to work with a-z/A-Z.
1644 (use str_utf8_find_nocase for unicode support)
1645 - The strings are treated as zero-terminated strings.
1646*/
1647const char *str_find_nocase(const char *haystack, const char *needle);
1648
1649/*
1650 Function: str_find
1651 Finds a string inside another string case sensitive.
1652
1653 Parameters:
1654 haystack - String to search in
1655 needle - String to search for
1656
1657 Returns:
1658 A pointer into haystack where the needle was found.
1659 Returns NULL if needle could not be found.
1660
1661 Remarks:
1662 - The strings are treated as zero-terminated strings.
1663*/
1664const char *str_find(const char *haystack, const char *needle);
1665
1680bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end);
1681
1696const char *str_rchr(const char *haystack, char needle);
1697
1712int str_countchr(const char *haystack, char needle);
1713
1724void str_hex(char *dst, int dst_size, const void *data, int data_size);
1725
1740void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line = 12);
1741
1742/*
1743 Function: str_hex_decode
1744 Takes a hex string *without spaces between bytes* and returns a
1745 byte array.
1746
1747 Parameters:
1748 dst - Buffer for the byte array
1749 dst_size - size of the buffer
1750 data - String to decode
1751
1752 Returns:
1753 2 - String doesn't exactly fit the buffer
1754 1 - Invalid character in string
1755 0 - Success
1756
1757 Remarks:
1758 - The contents of the buffer is only valid on success
1759*/
1760int str_hex_decode(void *dst, int dst_size, const char *src);
1761
1762/*
1763 Function: str_base64
1764 Takes a datablock and generates the base64 encoding of it.
1765
1766 Parameters:
1767 dst - Buffer to fill with base64 data
1768 dst_size - Size of the buffer
1769 data - Data to turn into base64
1770 data - Size of the data
1771
1772 Remarks:
1773 - The destination buffer will be zero-terminated
1774*/
1775void str_base64(char *dst, int dst_size, const void *data, int data_size);
1776
1777/*
1778 Function: str_base64_decode
1779 Takes a base64 string without any whitespace and correct
1780 padding and returns a byte array.
1781
1782 Parameters:
1783 dst - Buffer for the byte array
1784 dst_size - Size of the buffer
1785 data - String to decode
1786
1787 Returns:
1788 <0 - Error
1789 >= 0 - Success, length of the resulting byte buffer
1790
1791 Remarks:
1792 - The contents of the buffer is only valid on success
1793*/
1794int str_base64_decode(void *dst, int dst_size, const char *data);
1795
1796/*
1797 Function: str_timestamp
1798 Copies a time stamp in the format year-month-day_hour-minute-second to the string.
1799
1800 Parameters:
1801 buffer - Pointer to a buffer that shall receive the time stamp string.
1802 buffer_size - Size of the buffer.
1803
1804 Remarks:
1805 - Guarantees that buffer string will contain zero-termination.
1806*/
1807void str_timestamp(char *buffer, int buffer_size);
1808void str_timestamp_format(char *buffer, int buffer_size, const char *format)
1809 GNUC_ATTRIBUTE((format(strftime, 3, 0)));
1810void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
1811 GNUC_ATTRIBUTE((format(strftime, 4, 0)));
1812
1825bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
1826 GNUC_ATTRIBUTE((format(strftime, 2, 0)));
1827
1828#define FORMAT_TIME "%H:%M:%S"
1829#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
1830#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
1831
1832enum
1833{
1840};
1841
1842/*
1843 Function: str_times
1844 Formats a time string.
1845
1846 Parameters:
1847 centisecs - Time in centiseconds, minimum value clamped to 0
1848 format - Format of the time string, see enum above, for example TIME_DAYS
1849 buffer - Pointer to a buffer that shall receive the time stamp string.
1850 buffer_size - Size of the buffer.
1851
1852 Returns:
1853 Number of bytes written, -1 on invalid format or buffer_size <= 0
1854
1855 Remarks:
1856 - Guarantees that buffer string will contain zero-termination, assuming
1857 buffer_size > 0.
1858*/
1859int str_time(int64_t centisecs, int format, char *buffer, int buffer_size);
1860int str_time_float(float secs, int format, char *buffer, int buffer_size);
1861
1862/*
1863 Function: str_escape
1864 Escapes \ and " characters in a string.
1865
1866 Parameters:
1867 dst - Destination array pointer, gets increased, will point to
1868 the terminating null.
1869 src - Source array
1870 end - End of destination array
1871*/
1872void str_escape(char **dst, const char *src, const char *end);
1873
1892void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
1893
1906void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user);
1907
1922int fs_makedir(const char *path);
1923
1937int fs_removedir(const char *path);
1938
1950int fs_makedir_rec_for(const char *path);
1951
1969int fs_storage_path(const char *appname, char *path, int max);
1970
1983int fs_is_file(const char *path);
1984
1997int fs_is_dir(const char *path);
1998
2010int fs_is_relative_path(const char *path);
2011
2023int fs_chdir(const char *path);
2024
2037char *fs_getcwd(char *buffer, int buffer_size);
2038
2053const char *fs_filename(const char *path);
2054
2070void fs_split_file_extension(const char *filename, char *name, size_t name_size, char *extension = nullptr, size_t extension_size = 0);
2071
2083int fs_parent_dir(char *path);
2084
2097int fs_remove(const char *filename);
2098
2111int fs_rename(const char *oldname, const char *newname);
2112
2127int fs_file_time(const char *name, time_t *created, time_t *modified);
2128
2129/*
2130 Group: Undocumented
2131*/
2132
2133/*
2134 Function: net_tcp_connect_non_blocking
2135
2136 DOCTODO: serp
2137*/
2139
2140/*
2141 Function: net_set_non_blocking
2142
2143 DOCTODO: serp
2144*/
2146
2147/*
2148 Function: net_set_non_blocking
2149
2150 DOCTODO: serp
2151*/
2152int net_set_blocking(NETSOCKET sock);
2153
2154/*
2155 Function: net_errno
2156
2157 DOCTODO: serp
2158*/
2159int net_errno();
2160
2161/*
2162 Function: net_would_block
2163
2164 DOCTODO: serp
2165*/
2166int net_would_block();
2167
2168int net_socket_read_wait(NETSOCKET sock, int time);
2169
2179void swap_endian(void *data, unsigned elem_size, unsigned num);
2180
2181typedef struct
2182{
2184 uint64_t sent_bytes;
2186 uint64_t recv_bytes;
2187} NETSTATS;
2188
2189void net_stats(NETSTATS *stats);
2190
2191int str_toint(const char *str);
2192bool str_toint(const char *str, int *out);
2193int str_toint_base(const char *str, int base);
2194unsigned long str_toulong_base(const char *str, int base);
2195int64_t str_toint64_base(const char *str, int base = 10);
2196float str_tofloat(const char *str);
2197bool str_tofloat(const char *str, float *out);
2198
2210int str_isspace(char c);
2211
2212char str_uppercase(char c);
2213
2214bool str_isnum(char c);
2215
2216int str_isallnum(const char *str);
2217
2218int str_isallnum_hex(const char *str);
2219
2220unsigned str_quickhash(const char *str);
2221
2222int str_utf8_to_skeleton(const char *str, int *buf, int buf_len);
2223
2224/*
2225 Function: str_utf8_comp_confusable
2226 Compares two strings for visual appearance.
2227
2228 Parameters:
2229 str1 - String to compare.
2230 str2 - String to compare.
2231
2232 Returns:
2233 0 if the strings are confusable.
2234 !=0 otherwise.
2235*/
2236int str_utf8_comp_confusable(const char *str1, const char *str2);
2237
2238/*
2239 Function: str_utf8_tolower
2240 Converts the given Unicode codepoint to lowercase (locale insensitive).
2241
2242 Parameters:
2243 code - Unicode codepoint to convert.
2244
2245 Returns:
2246 Lowercase codepoint
2247*/
2248int str_utf8_tolower(int code);
2249
2250/*
2251 Function: str_utf8_comp_nocase
2252 Compares two utf8 strings case insensitively.
2253
2254 Parameters:
2255 a - String to compare.
2256 b - String to compare.
2257
2258 Returns:
2259 <0 - String a is less than string b
2260 0 - String a is equal to string b
2261 >0 - String a is greater than string b
2262*/
2263int str_utf8_comp_nocase(const char *a, const char *b);
2264
2265/*
2266 Function: str_utf8_comp_nocase_num
2267 Compares up to num bytes of two utf8 strings case insensitively.
2268
2269 Parameters:
2270 a - String to compare.
2271 b - String to compare.
2272 num - Maximum bytes to compare
2273
2274 Returns:
2275 <0 - String a is less than string b
2276 0 - String a is equal to string b
2277 >0 - String a is greater than string b
2278*/
2279int str_utf8_comp_nocase_num(const char *a, const char *b, int num);
2280
2281/*
2282 Function: str_utf8_find_nocase
2283 Finds a utf8 string inside another utf8 string case insensitively.
2284
2285 Parameters:
2286 haystack - String to search in
2287 needle - String to search for
2288 end - A pointer that will be set to a pointer into haystack directly behind the
2289 last character where the needle was found. Will be set to nullptr if needle
2290 could not be found. Optional parameter.
2291
2292 Returns:
2293 A pointer into haystack where the needle was found.
2294 Returns NULL if needle could not be found.
2295
2296 Remarks:
2297 - The strings are treated as zero-terminated strings.
2298*/
2299const char *str_utf8_find_nocase(const char *haystack, const char *needle, const char **end = nullptr);
2300
2301/*
2302 Function: str_utf8_isspace
2303 Checks whether the given Unicode codepoint renders as space.
2304
2305 Parameters:
2306 code - Unicode codepoint to check.
2307
2308 Returns:
2309 0 if the codepoint does not render as space, != 0 if it does.
2310*/
2311int str_utf8_isspace(int code);
2312
2313int str_utf8_isstart(char c);
2314
2315/*
2316 Function: str_utf8_skip_whitespaces
2317 Skips leading characters that render as spaces.
2318
2319 Parameters:
2320 str - Pointer to the string.
2321
2322 Returns:
2323 Pointer to the first non-whitespace character found
2324 within the string.
2325
2326 Remarks:
2327 - The strings are treated as zero-terminated strings.
2328*/
2329const char *str_utf8_skip_whitespaces(const char *str);
2330
2331/*
2332 Function: str_utf8_trim_right
2333 Removes trailing characters that render as spaces by modifying
2334 the string in-place.
2335
2336 Parameters:
2337 param - Pointer to the string.
2338
2339 Remarks:
2340 - The strings are treated as zero-terminated strings.
2341 - The string is modified in-place.
2342*/
2343void str_utf8_trim_right(char *param);
2344
2345/*
2346 Function: str_utf8_rewind
2347 Moves a cursor backwards in an utf8 string
2348
2349 Parameters:
2350 str - utf8 string
2351 cursor - position in the string
2352
2353 Returns:
2354 New cursor position.
2355
2356 Remarks:
2357 - Won't move the cursor less then 0
2358*/
2359int str_utf8_rewind(const char *str, int cursor);
2360
2361/*
2362 Function: str_utf8_fix_truncation
2363 Fixes truncation of a Unicode character at the end of a UTF-8
2364 string.
2365
2366 Returns:
2367 The new string length.
2368
2369 Parameters:
2370 str - utf8 string
2371*/
2372int str_utf8_fix_truncation(char *str);
2373
2374/*
2375 Function: str_utf8_forward
2376 Moves a cursor forwards in an utf8 string
2377
2378 Parameters:
2379 str - utf8 string
2380 cursor - position in the string
2381
2382 Returns:
2383 New cursor position.
2384
2385 Remarks:
2386 - Won't move the cursor beyond the zero termination marker
2387*/
2388int str_utf8_forward(const char *str, int cursor);
2389
2390/*
2391 Function: str_utf8_decode
2392 Decodes a utf8 codepoint
2393
2394 Parameters:
2395 ptr - Pointer to a utf8 string. This pointer will be moved forward.
2396
2397 Returns:
2398 The Unicode codepoint. -1 for invalid input and 0 for end of string.
2399
2400 Remarks:
2401 - This function will also move the pointer forward.
2402 - You may call this function again after an error occurred.
2403*/
2404int str_utf8_decode(const char **ptr);
2405
2406/*
2407 Function: str_utf8_encode
2408 Encode an utf8 character
2409
2410 Parameters:
2411 ptr - Pointer to a buffer that should receive the data. Should be able to hold at least 4 bytes.
2412
2413 Returns:
2414 Number of bytes put into the buffer.
2415
2416 Remarks:
2417 - Does not do zero termination of the string.
2418*/
2419int str_utf8_encode(char *ptr, int chr);
2420
2421/*
2422 Function: str_utf8_check
2423 Checks if a strings contains just valid utf8 characters.
2424
2425 Parameters:
2426 str - Pointer to a possible utf8 string.
2427
2428 Returns:
2429 0 - invalid characters found.
2430 1 - only valid characters found.
2431
2432 Remarks:
2433 - The string is treated as zero-terminated utf8 string.
2434*/
2435int str_utf8_check(const char *str);
2436
2437/*
2438 Function: str_utf8_copy_num
2439 Copies a number of utf8 characters from one string to another.
2440
2441 Parameters:
2442 dst - Pointer to a buffer that shall receive the string.
2443 src - String to be copied.
2444 dst_size - Size of the buffer dst.
2445 num - maximum number of utf8 characters to be copied.
2446
2447 Remarks:
2448 - The strings are treated as zero-terminated strings.
2449 - Garantees that dst string will contain zero-termination.
2450*/
2451void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num);
2452
2453/*
2454 Function: str_utf8_stats
2455 Determines the byte size and utf8 character count of a utf8 string.
2456
2457 Parameters:
2458 str - Pointer to the string.
2459 max_size - Maximum number of bytes to count.
2460 max_count - Maximum number of utf8 characters to count.
2461 size - Pointer to store size (number of non-zero bytes) of the string.
2462 count - Pointer to store count of utf8 characters of the string.
2463
2464 Remarks:
2465 - The string is treated as zero-terminated utf8 string.
2466 - It's the user's responsibility to make sure the bounds are aligned.
2467*/
2468void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count);
2469
2481size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset);
2482
2494size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset);
2495
2496/*
2497 Function: str_next_token
2498 Writes the next token after str into buf, returns the rest of the string.
2499
2500 Parameters:
2501 str - Pointer to string.
2502 delim - Delimiter for tokenization.
2503 buffer - Buffer to store token in.
2504 buffer_size - Size of the buffer.
2505
2506 Returns:
2507 Pointer to rest of the string.
2508
2509 Remarks:
2510 - The token is always null-terminated.
2511*/
2512const char *str_next_token(const char *str, const char *delim, char *buffer, int buffer_size);
2513
2514/*
2515 Function: str_in_list
2516 Checks if needle is in list delimited by delim
2517
2518 Parameters:
2519 list - List
2520 delim - List delimiter.
2521 needle - Item that is being looked for.
2522
2523 Returns:
2524 1 - Item is in list.
2525 0 - Item isn't in list.
2526*/
2527int str_in_list(const char *list, const char *delim, const char *needle);
2528
2541unsigned bytes_be_to_uint(const unsigned char *bytes);
2542
2554void uint_to_bytes_be(unsigned char *bytes, unsigned value);
2555
2568int pid();
2569
2580void cmdline_fix(int *argc, const char ***argv);
2581
2590void cmdline_free(int argc, const char **argv);
2591
2592#if defined(CONF_FAMILY_WINDOWS)
2598typedef void *PROCESS;
2604constexpr PROCESS INVALID_PROCESS = nullptr;
2605#else
2611typedef pid_t PROCESS;
2618#endif
2619#if !defined(CONF_PLATFORM_ANDROID)
2629{
2633 FOREGROUND,
2634
2638 BACKGROUND,
2639};
2640
2651PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state);
2652
2662int kill_process(PROCESS process);
2663
2674bool is_process_alive(PROCESS process);
2675
2688int open_link(const char *link);
2689
2702int open_file(const char *path);
2703#endif // !defined(CONF_PLATFORM_ANDROID)
2704
2720void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length);
2721
2730[[nodiscard]] int secure_random_init();
2731
2740
2753void secure_random_password(char *buffer, unsigned length, unsigned pw_length);
2754
2763void secure_random_fill(void *bytes, unsigned length);
2764
2774int secure_rand();
2775
2786int secure_rand_below(int below);
2787
2798bool os_version_str(char *version, size_t length);
2799
2814void os_locale_str(char *locale, size_t length);
2815
2816#if defined(CONF_EXCEPTION_HANDLING)
2827void init_exception_handler();
2828
2836void set_exception_handler_log_file(const char *log_file_path);
2837#endif
2838
2846std::chrono::nanoseconds time_get_nanoseconds();
2847
2848int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds);
2849
2857{
2859 const char **m_ppArgv;
2860
2861public:
2862 CCmdlineFix(int *pArgc, const char ***pppArgv)
2863 {
2864 cmdline_fix(pArgc, pppArgv);
2865 m_Argc = *pArgc;
2866 m_ppArgv = *pppArgv;
2867 }
2869 {
2871 }
2872};
2873
2874#if defined(CONF_FAMILY_WINDOWS)
2888std::wstring windows_utf8_to_wide(const char *str);
2889
2903std::optional<std::string> windows_wide_to_utf8(const wchar_t *wide_str);
2904
2915class CWindowsComLifecycle
2916{
2917public:
2918 CWindowsComLifecycle(bool HasWindow);
2919 ~CWindowsComLifecycle();
2920};
2921
2935bool shell_register_protocol(const char *protocol_name, const char *executable, bool *updated);
2936
2952bool shell_register_extension(const char *extension, const char *description, const char *executable_name, const char *executable, bool *updated);
2953
2967bool shell_register_application(const char *name, const char *executable, bool *updated);
2968
2983bool shell_unregister_class(const char *shell_class, bool *updated);
2984
2997bool shell_unregister_application(const char *executable, bool *updated);
2998
3006void shell_update();
3007#endif
3008
3009template<>
3010struct std::hash<NETADDR>
3011{
3012 size_t operator()(const NETADDR &Addr) const noexcept;
3013};
3014
3015#endif
Definition: system.h:2857
~CCmdlineFix()
Definition: system.h:2868
int m_Argc
Definition: system.h:2858
const char ** m_ppArgv
Definition: system.h:2859
CCmdlineFix(int *pArgc, const char ***pppArgv)
Definition: system.h:2862
void dbg_break()
Definition: system.cpp:150
bool dbg_assert_has_failed()
Definition: system.cpp:125
void dbg_msg(const char *sys, const char *fmt,...)
Definition: system.cpp:164
void aio_write_newline_unlocked(ASYNCIO *aio)
Definition: system.cpp:741
IOHANDLE io_current_exe()
Definition: system.cpp:452
void aio_wait(ASYNCIO *aio)
Definition: system.cpp:772
void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:684
int io_flush(IOHANDLE io)
Definition: system.cpp:414
ESeekOrigin
Definition: system.h:246
int64_t io_tell(IOHANDLE io)
Definition: system.cpp:372
IOHANDLE io_stderr()
Definition: system.cpp:447
IOHANDLE io_open(const char *filename, int flags)
Definition: system.cpp:202
int io_close(IOHANDLE io)
Definition: system.cpp:409
char * io_read_all_str(IOHANDLE io)
Definition: system.cpp:326
void aio_write(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:734
void aio_write_newline(ASYNCIO *aio)
Definition: system.cpp:750
int io_skip(IOHANDLE io, int64_t size)
Definition: system.cpp:342
int aio_error(ASYNCIO *aio)
Definition: system.cpp:757
void aio_free(ASYNCIO *aio)
Definition: system.cpp:788
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size)
Definition: system.cpp:395
bool io_write_newline(IOHANDLE io)
Definition: system.cpp:400
bool io_read_all(IOHANDLE io, void **result, unsigned *result_len)
Definition: system.cpp:269
void aio_lock(ASYNCIO *aio)
Definition: system.cpp:673
void aio_close(ASYNCIO *aio)
Definition: system.cpp:763
int io_sync(IOHANDLE io)
Definition: system.cpp:419
int io_seek(IOHANDLE io, int64_t offset, ESeekOrigin origin)
Definition: system.cpp:347
IOHANDLE io_stdin()
Definition: system.cpp:437
int io_error(IOHANDLE io)
Definition: system.cpp:432
IOHANDLE io_stdout()
Definition: system.cpp:442
ASYNCIO * aio_new(IOHANDLE io)
Definition: system.cpp:616
void aio_unlock(ASYNCIO *aio)
Definition: system.cpp:678
int64_t io_length(IOHANDLE io)
Definition: system.cpp:381
unsigned io_read(IOHANDLE io, void *buffer, unsigned size)
Definition: system.cpp:264
@ IOSEEK_END
Definition: system.h:264
@ IOSEEK_CUR
Definition: system.h:258
@ IOSEEK_START
Definition: system.h:252
@ IOFLAG_APPEND
Definition: system.h:239
@ IOFLAG_WRITE
Definition: system.h:233
@ IOFLAG_READ
Definition: system.h:227
void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user)
Definition: system.cpp:2146
const char * fs_filename(const char *path)
Definition: system.cpp:2463
void fs_split_file_extension(const char *filename, char *name, size_t name_size, char *extension=nullptr, size_t extension_size=0)
Definition: system.cpp:2473
int fs_is_relative_path(const char *path)
Definition: system.cpp:2418
int fs_is_file(const char *path)
Definition: system.cpp:2390
int fs_removedir(const char *path)
Definition: system.cpp:2376
int fs_parent_dir(char *path)
Definition: system.cpp:2496
void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user)
Definition: system.cpp:2198
char * fs_getcwd(char *buffer, int buffer_size)
Definition: system.cpp:2438
int fs_is_dir(const char *path)
Definition: system.cpp:2404
int fs_file_time(const char *name, time_t *created, time_t *modified)
Definition: system.cpp:2537
int fs_makedir_rec_for(const char *path)
Definition: system.cpp:2332
int fs_storage_path(const char *appname, char *path, int max)
Definition: system.cpp:2265
int fs_chdir(const char *path)
Definition: system.cpp:2428
int fs_remove(const char *filename)
Definition: system.cpp:2513
int fs_rename(const char *oldname, const char *newname)
Definition: system.cpp:2523
int fs_makedir(const char *path)
Definition: system.cpp:2353
void mem_zero(T *block, size_t size)
Definition: system.h:178
void mem_copy(void *dest, const void *source, size_t size)
Definition: system.cpp:174
bool mem_has_null(const void *block, size_t size)
Definition: system.cpp:189
void mem_move(void *dest, const void *source, size_t size)
Definition: system.cpp:179
int mem_comp(const void *a, const void *b, size_t size)
Definition: system.cpp:184
int UNIXSOCKET
Definition: system.h:806
bool net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port)
Definition: system.cpp:1147
int net_addr_comp_noport(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1072
void net_init()
Definition: system.cpp:2098
int net_addr_comp(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1062
struct sockaddr_un UNIXSOCKETADDR
Definition: system.h:810
int net_tcp_close(NETSOCKET sock)
Definition: system.cpp:2075
int net_tcp_listen(NETSOCKET sock, int backlog)
Definition: system.cpp:1960
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr)
Definition: system.cpp:1970
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr)
Definition: system.cpp:2017
NETSOCKET net_tcp_create(NETADDR bindaddr)
Definition: system.cpp:1883
int net_tcp_send(NETSOCKET sock, const void *data, int size)
Definition: system.cpp:2051
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize)
Definition: system.cpp:2063
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size)
Definition: system.cpp:1675
int net_udp_close(NETSOCKET sock)
Definition: system.cpp:1878
int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size)
Definition: system.cpp:2112
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path)
Definition: system.cpp:2117
UNIXSOCKET net_unix_create_unnamed()
Definition: system.cpp:2107
void net_unix_close(UNIXSOCKET sock)
Definition: system.cpp:2124
void secure_random_password(char *buffer, unsigned length, unsigned pw_length)
Definition: system.cpp:4431
void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length)
Definition: system.cpp:4411
int secure_rand()
Definition: system.cpp:4471
int secure_random_init()
Definition: system.cpp:4352
int secure_random_uninit()
Definition: system.cpp:4382
void secure_random_fill(void *bytes, unsigned length)
Definition: system.cpp:4447
int secure_rand_below(int below)
Definition: system.cpp:4490
void sphore_signal(SEMAPHORE *sem)
Definition: system.cpp:955
void sphore_destroy(SEMAPHORE *sem)
Definition: system.cpp:959
void sphore_init(SEMAPHORE *sem)
Definition: system.cpp:942
void sphore_wait(SEMAPHORE *sem)
Definition: system.cpp:946
bool os_version_str(char *version, size_t length)
Definition: system.cpp:4506
int kill_process(PROCESS process)
Definition: system.cpp:4244
bool is_process_alive(PROCESS process)
Definition: system.cpp:4264
EShellExecuteWindowState
Definition: system.h:2629
int open_link(const char *link)
Definition: system.cpp:4277
constexpr PROCESS INVALID_PROCESS
Definition: system.h:2617
void cmdline_free(int argc, const char **argv)
Definition: system.cpp:4186
void os_locale_str(char *locale, size_t length)
Definition: system.cpp:4585
void cmdline_fix(int *argc, const char ***argv)
Definition: system.cpp:4148
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state)
Definition: system.cpp:4195
int open_file(const char *path)
Definition: system.cpp:4317
int pid()
Definition: system.cpp:4139
pid_t PROCESS
Definition: system.h:2611
const char * str_rchr(const char *haystack, char needle)
Definition: system.cpp:3238
char * str_skip_to_whitespace(char *str)
Definition: system.cpp:2927
int str_length(const char *str)
Definition: system.cpp:2795
void str_sanitize(char *str)
Definition: system.cpp:2873
const char * str_startswith(const char *str, const char *prefix)
Definition: system.cpp:3029
bool str_has_cc(const char *str)
Definition: system.cpp:2846
void str_sanitize_cc(char *str)
Definition: system.cpp:2861
const char * str_skip_whitespaces_const(const char *str)
Definition: system.cpp:2948
const char * str_skip_to_whitespace_const(const char *str)
Definition: system.cpp:2934
int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
Definition: system.cpp:2800
int str_comp_num(const char *a, const char *b, int num)
Definition: system.cpp:2979
void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2768
int str_comp_filenames(const char *a, const char *b)
Definition: system.cpp:2984
int str_comp_nocase(const char *a, const char *b)
Definition: system.cpp:2956
void str_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2785
bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end)
Definition: system.cpp:3206
int str_countchr(const char *haystack, char needle)
Definition: system.cpp:3243
int str_comp(const char *a, const char *b)
Definition: system.cpp:2974
void str_append(char *dst, const char *src, int dst_size)
Definition: system.cpp:2744
void str_clean_whitespaces(char *str)
Definition: system.cpp:2896
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2761
char * str_skip_whitespaces(char *str)
Definition: system.cpp:2941
int str_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:2965
int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len)
Definition: system.cpp:3148
int str_isspace(char c)
Definition: system.cpp:3623
const char * str_trim_words(const char *str, int words)
Definition: system.cpp:2833
void thread_wait(void *thread)
Definition: system.cpp:850
void * thread_init(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:824
void thread_yield()
Definition: system.cpp:862
void thread_init_and_detach(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:884
void thread_detach(void *thread)
Definition: system.cpp:873
std::chrono::nanoseconds time_get_nanoseconds()
Definition: system.cpp:4701
ETimeSeason
Definition: system.h:770
void set_new_tick()
Definition: system.cpp:967
int64_t time_freq()
Definition: system.cpp:994
int time_houroftheday()
Definition: system.cpp:2659
int64_t time_timestamp()
Definition: system.cpp:2641
ETimeSeason time_season()
Definition: system.cpp:2697
int64_t time_get()
Definition: system.cpp:982
int64_t time_get_impl()
Definition: system.cpp:977
@ SEASON_AUTUMN
Definition: system.h:773
@ SEASON_WINTER
Definition: system.h:774
@ SEASON_SPRING
Definition: system.h:771
@ SEASON_HALLOWEEN
Definition: system.h:776
@ SEASON_XMAS
Definition: system.h:777
@ SEASON_EASTER
Definition: system.h:775
@ SEASON_SUMMER
Definition: system.h:772
@ SEASON_NEWYEAR
Definition: system.h:778
void * IOHANDLE
Definition: logger.h:11
Definition: system.cpp:493
void * thread
Definition: system.cpp:497
unsigned char * buffer
Definition: system.cpp:499
IOHANDLE io
Definition: system.cpp:495
Definition: types.h:67
Definition: system.cpp:110
Definition: system.h:2182
uint64_t recv_packets
Definition: system.h:2185
uint64_t recv_bytes
Definition: system.h:2186
uint64_t sent_packets
Definition: system.h:2183
uint64_t sent_bytes
Definition: system.h:2184
void str_utf8_trim_right(char *param)
Definition: system.cpp:3809
void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line=12)
Definition: system.cpp:3270
int str_utf8_comp_nocase(const char *a, const char *b)
Definition: system.cpp:3711
void swap_endian(void *data, unsigned elem_size, unsigned num)
Definition: system.cpp:2563
size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset)
Definition: system.cpp:4057
void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num)
Definition: system.cpp:4004
NETSOCKET net_udp_create(NETADDR bindaddr)
Definition: system.cpp:1577
void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler)
Definition: system.cpp:159
int str_isallnum(const char *str)
Definition: system.cpp:3640
int str_utf8_forward(const char *str, int cursor)
Definition: system.cpp:3869
const char * str_next_token(const char *str, const char *delim, char *buffer, int buffer_size)
Definition: system.cpp:4106
int str_utf8_decode(const char **ptr)
Definition: system.cpp:3924
unsigned long str_toulong_base(const char *str, int base)
Definition: system.cpp:3684
const char * str_find_nocase(const char *haystack, const char *needle)
Definition: system.cpp:3168
int net_would_block()
Definition: system.cpp:2089
void str_base64(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3362
int net_host_lookup(const char *hostname, NETADDR *addr, int types)
Definition: system.cpp:1252
int str_utf8_encode(char *ptr, int chr)
Definition: system.cpp:3879
int str_utf8_dist(const char *a, const char *b)
Definition: system.cpp:3092
int str_toint_base(const char *str, int base)
Definition: system.cpp:3679
int str_utf8_isstart(char c)
Definition: system.cpp:3834
bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
Definition: system.cpp:3531
void str_escape(char **dst, const char *src, const char *end)
Definition: system.cpp:3602
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
Definition: system.cpp:1326
int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len)
Definition: system.cpp:3112
const char * str_utf8_skip_whitespaces(const char *str)
Definition: system.cpp:3789
void str_sanitize_filename(char *str)
Definition: system.cpp:2884
int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr)
Definition: system.cpp:2040
std::function< void(const char *message)> DBG_ASSERT_HANDLER
Definition: system.h:116
int net_set_non_blocking(NETSOCKET sock)
Definition: system.cpp:1950
int str_in_list(const char *list, const char *delim, const char *needle)
Definition: system.cpp:4092
int str_utf8_comp_confusable(const char *str1, const char *str2)
Definition: confusables.cpp:83
int net_socket_type(NETSOCKET sock)
Definition: system.cpp:1572
void str_timestamp(char *buffer, int buffer_size)
Definition: system.cpp:3526
void uint_to_bytes_be(unsigned char *bytes, unsigned value)
Definition: system.cpp:4131
int str_format_int(char *buffer, size_t buffer_size, int value)
Definition: system.cpp:2812
int str_base64_decode(void *dst, int dst_size, const char *data)
Definition: system.cpp:3439
@ TIME_SECS_CENTISECS
Definition: system.h:1839
@ TIME_HOURS_CENTISECS
Definition: system.h:1837
@ TIME_DAYS
Definition: system.h:1834
@ TIME_MINS
Definition: system.h:1836
@ TIME_HOURS
Definition: system.h:1835
@ TIME_MINS_CENTISECS
Definition: system.h:1838
int str_time_float(float secs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3597
const NETADDR NETADDR_ZEROED
Definition: system.cpp:1002
#define GNUC_ATTRIBUTE(x)
Definition: system.h:88
int net_errno()
Definition: system.cpp:2080
int str_toint(const char *str)
Definition: system.cpp:3662
void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count)
Definition: system.cpp:4022
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
Definition: system.h:1292
int str_hex_decode(void *dst, int dst_size, const char *src)
Definition: system.cpp:3345
bool str_isnum(char c)
Definition: system.cpp:3635
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3519
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3512
float str_tofloat(const char *str)
Definition: system.cpp:3694
void str_hex(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3255
void net_stats(NETSTATS *stats)
Definition: system.cpp:3618
unsigned str_quickhash(const char *str)
Definition: system.cpp:4070
int net_socket_read_wait(NETSOCKET sock, int time)
Definition: system.cpp:2589
void dbg_assert_imp(const char *filename, int line, bool test, const char *msg)
Definition: system.cpp:130
int net_set_blocking(NETSOCKET sock)
Definition: system.cpp:1955
sem_t SEMAPHORE
Definition: system.h:681
size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset)
Definition: system.cpp:4042
int net_addr_from_str(NETADDR *addr, const char *string)
Definition: system.cpp:1375
int str_utf8_check(const char *str)
Definition: system.cpp:3991
const char * str_utf8_find_nocase(const char *haystack, const char *needle, const char **end=nullptr)
Definition: system.cpp:3751
#define str_format
Definition: system.h:1311
int str_isallnum_hex(const char *str)
Definition: system.cpp:3651
int str_utf8_isspace(int code)
Definition: system.cpp:3778
int str_time(int64_t centisecs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3550
const char * str_startswith_nocase(const char *str, const char *prefix)
Definition: system.cpp:3016
int str_utf8_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:3727
const char * str_endswith_nocase(const char *str, const char *suffix)
Definition: system.cpp:3042
unsigned bytes_be_to_uint(const unsigned char *bytes)
Definition: system.cpp:4126
int str_utf8_rewind(const char *str, int cursor)
Definition: system.cpp:3841
int str_utf8_fix_truncation(char *str)
Definition: system.cpp:3852
const char * str_endswith(const char *str, const char *suffix)
Definition: system.cpp:3062
const char * str_find(const char *haystack, const char *needle)
Definition: system.cpp:3187
char str_uppercase(char c)
Definition: system.cpp:3628
int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data)
Definition: system.cpp:1800
int64_t str_toint64_base(const char *str, int base=10)
Definition: system.cpp:3689
int str_utf8_tolower(int code)
Definition: tolower.cpp:12
int str_utf8_to_skeleton(const char *str, int *buf, int buf_len)
Definition: confusables.cpp:66
int(* FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user)
Definition: types.h:29
int(* FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user)
Definition: types.h:20
float length(const vector2_base< float > &a)
Definition: vmath.h:104