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
259};
260
273IOHANDLE io_open(const char *filename, int flags);
274
286unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
287
300void io_read_all(IOHANDLE io, void **result, unsigned *result_len);
301
316char *io_read_all_str(IOHANDLE io);
317
328int io_skip(IOHANDLE io, int size);
329
341int io_seek(IOHANDLE io, int offset, int origin);
342
352long int io_tell(IOHANDLE io);
353
363long int io_length(IOHANDLE io);
364
376unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
377
388
398int io_close(IOHANDLE io);
399
409int io_flush(IOHANDLE io);
410
420int io_sync(IOHANDLE io);
421
431int io_error(IOHANDLE io);
432
443
454
465
474
480typedef struct ASYNCIO ASYNCIO;
481
492
501void aio_lock(ASYNCIO *aio);
502
511void aio_unlock(ASYNCIO *aio);
512
522void aio_write(ASYNCIO *aio, const void *buffer, unsigned size);
523
531void aio_write_newline(ASYNCIO *aio);
532
543void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size);
544
554
569int aio_error(ASYNCIO *aio);
570
578void aio_close(ASYNCIO *aio);
579
587void aio_wait(ASYNCIO *aio);
588
596void aio_free(ASYNCIO *aio);
597
617void *thread_init(void (*threadfunc)(void *), void *user, const char *name);
618
626void thread_wait(void *thread);
627
633void thread_yield();
634
644void thread_detach(void *thread);
645
655void thread_init_and_detach(void (*threadfunc)(void *), void *user, const char *name);
656
662#if defined(CONF_FAMILY_WINDOWS)
663typedef void *SEMAPHORE;
664#elif defined(CONF_PLATFORM_MACOS)
665#include <semaphore.h>
666typedef sem_t *SEMAPHORE;
667#elif defined(CONF_FAMILY_UNIX)
668#include <semaphore.h>
669typedef sem_t SEMAPHORE;
670#else
671#error not implemented on this platform
672#endif
673
677void sphore_init(SEMAPHORE *sem);
681void sphore_wait(SEMAPHORE *sem);
685void sphore_signal(SEMAPHORE *sem);
689void sphore_destroy(SEMAPHORE *sem);
690
700void set_new_tick();
701
713int64_t time_get_impl();
714
727int64_t time_get();
728
734int64_t time_freq();
735
743int64_t time_timestamp();
744
753
758{
768
779
784extern const NETADDR NETADDR_ZEROED;
785
790#ifdef CONF_FAMILY_UNIX
794typedef int UNIXSOCKET;
798typedef struct sockaddr_un UNIXSOCKETADDR;
799#endif
800
808void net_init();
809
810/*
811 Function: net_host_lookup
812 Does a hostname lookup by name and fills out the passed
813 NETADDR struct with the received details.
814
815 Returns:
816 0 on success.
817*/
818int net_host_lookup(const char *hostname, NETADDR *addr, int types);
819
832int net_addr_comp(const NETADDR *a, const NETADDR *b);
833
846int net_addr_comp_noport(const NETADDR *a, const NETADDR *b);
847
862bool net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port);
863
887int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size);
888
897int net_addr_from_str(NETADDR *addr, const char *string);
898
904/*
905 Function: net_socket_type
906 Determine a socket's type.
907
908 Parameters:
909 sock - Socket whose type should be determined.
910
911 Returns:
912 The socket type, a bitset of `NETTYPE_IPV4`, `NETTYPE_IPV6` and
913 `NETTYPE_WEBSOCKET_IPV4`.
914*/
915int net_socket_type(NETSOCKET sock);
916
917/*
918 Function: net_udp_create
919 Creates a UDP socket and binds it to a port.
920
921 Parameters:
922 bindaddr - Address to bind the socket to.
923
924 Returns:
925 On success it returns an handle to the socket. On failure it
926 returns NETSOCKET_INVALID.
927*/
929
943int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
944
945/*
946 Function: net_udp_recv
947 Receives a packet over an UDP socket.
948
949 Parameters:
950 sock - Socket to use.
951 addr - Pointer to an NETADDR that will receive the address.
952 data - Received data. Will be invalidated when this function is
953 called again.
954
955 Returns:
956 On success it returns the number of bytes received. Returns -1
957 on error.
958*/
959int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data);
960
970int net_udp_close(NETSOCKET sock);
971
987
998int net_tcp_listen(NETSOCKET sock, int backlog);
999
1011int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
1012
1024int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
1025
1037int net_tcp_send(NETSOCKET sock, const void *data, int size);
1038
1052int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
1053
1063int net_tcp_close(NETSOCKET sock);
1064
1065#if defined(CONF_FAMILY_UNIX)
1079
1092int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
1093
1102void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
1103
1111void net_unix_close(UNIXSOCKET sock);
1112
1113#elif defined(CONF_FAMILY_WINDOWS)
1114
1122std::string windows_format_system_message(unsigned long error);
1123
1124#endif
1125
1144void str_append(char *dst, const char *src, int dst_size);
1145
1157template<int N>
1158void str_append(char (&dst)[N], const char *src)
1159{
1160 str_append(dst, src, N);
1161}
1162
1177int str_copy(char *dst, const char *src, int dst_size);
1178
1190template<int N>
1191void str_copy(char (&dst)[N], const char *src)
1192{
1193 str_copy(dst, src, N);
1194}
1195
1209void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1210
1225void str_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1226
1236int str_length(const char *str);
1237
1254int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
1255 GNUC_ATTRIBUTE((format(printf, 3, 0)));
1256
1273int str_format(char *buffer, int buffer_size, const char *format, ...)
1274 GNUC_ATTRIBUTE((format(printf, 3, 4)));
1275
1276#if !defined(CONF_DEBUG)
1277int str_format_int(char *buffer, size_t buffer_size, int value);
1278
1279template<typename... Args>
1280int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
1281{
1282 static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
1283 return str_format(buffer, buffer_size, format, args...);
1284}
1285
1286template<>
1287inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
1288{
1289 if(strcmp(format, "%d") == 0)
1290 {
1291 return str_format_int(buffer, buffer_size, val);
1292 }
1293 else
1294 {
1295 return str_format(buffer, buffer_size, format, val);
1296 }
1297}
1298
1299#define str_format str_format_opt
1300#endif
1301
1315const char *str_trim_words(const char *str, int words);
1316
1328bool str_has_cc(const char *str);
1329
1339void str_sanitize_cc(char *str);
1340
1351void str_sanitize(char *str);
1352
1360void str_sanitize_filename(char *str);
1361
1371void str_clean_whitespaces(char *str);
1372
1386char *str_skip_to_whitespace(char *str);
1387
1392const char *str_skip_to_whitespace_const(const char *str);
1393
1407char *str_skip_whitespaces(char *str);
1408
1413const char *str_skip_whitespaces_const(const char *str);
1414
1430int str_comp_nocase(const char *a, const char *b);
1431
1449int str_comp_nocase_num(const char *a, const char *b, int num);
1450
1465int str_comp(const char *a, const char *b);
1466
1482int str_comp_num(const char *a, const char *b, int num);
1483
1498int str_comp_filenames(const char *a, const char *b);
1499
1500/*
1501 Function: str_startswith_nocase
1502 Checks case insensitive whether the string begins with a certain prefix.
1503
1504 Parameter:
1505 str - String to check.
1506 prefix - Prefix to look for.
1507
1508 Returns:
1509 A pointer to the string str after the string prefix, or 0 if
1510 the string prefix isn't a prefix of the string str.
1511
1512 Remarks:
1513 - The strings are treated as zero-terminated strings.
1514*/
1515const char *str_startswith_nocase(const char *str, const char *prefix);
1516
1530const char *str_startswith(const char *str, const char *prefix);
1531
1532/*
1533 Function: str_endswith_nocase
1534 Checks case insensitive whether the string ends with a certain suffix.
1535
1536 Parameter:
1537 str - String to check.
1538 suffix - Suffix to look for.
1539
1540 Returns:
1541 A pointer to the beginning of the suffix in the string str, or
1542 0 if the string suffix isn't a suffix of the string str.
1543
1544 Remarks:
1545 - The strings are treated as zero-terminated strings.
1546*/
1547const char *str_endswith_nocase(const char *str, const char *suffix);
1548
1549/*
1550 Function: str_endswith
1551 Checks case sensitive whether the string ends with a certain suffix.
1552
1553 Parameter:
1554 str - String to check.
1555 suffix - Suffix to look for.
1556
1557 Returns:
1558 A pointer to the beginning of the suffix in the string str, or
1559 0 if the string suffix isn't a suffix of the string str.
1560
1561 Remarks:
1562 - The strings are treated as zero-terminated strings.
1563*/
1564const char *str_endswith(const char *str, const char *suffix);
1565
1576int str_utf8_dist(const char *a, const char *b);
1577
1594int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len);
1595
1596/*
1597 Function: str_utf32_dist_buffer
1598 Computes the edit distance between two strings, allows buffers
1599 to be passed in.
1600
1601 Parameters:
1602 a - First string for the edit distance.
1603 a_len - Length of the first string.
1604 b - Second string for the edit distance.
1605 b_len - Length of the second string.
1606 buf - Buffer for the function.
1607 buf_len - Length of the buffer, must be at least as long as
1608 the length of both strings combined plus two.
1609
1610 Returns:
1611 The edit distance between the both strings.
1612
1613 Remarks:
1614 - The strings are treated as zero-terminated strings.
1615*/
1616int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len);
1617
1618/*
1619 Function: str_find_nocase
1620 Finds a string inside another string case insensitively.
1621
1622 Parameters:
1623 haystack - String to search in
1624 needle - String to search for
1625
1626 Returns:
1627 A pointer into haystack where the needle was found.
1628 Returns NULL if needle could not be found.
1629
1630 Remarks:
1631 - Only guaranteed to work with a-z/A-Z.
1632 (use str_utf8_find_nocase for unicode support)
1633 - The strings are treated as zero-terminated strings.
1634*/
1635const char *str_find_nocase(const char *haystack, const char *needle);
1636
1637/*
1638 Function: str_find
1639 Finds a string inside another string case sensitive.
1640
1641 Parameters:
1642 haystack - String to search in
1643 needle - String to search for
1644
1645 Returns:
1646 A pointer into haystack where the needle was found.
1647 Returns NULL if needle could not be found.
1648
1649 Remarks:
1650 - The strings are treated as zero-terminated strings.
1651*/
1652const char *str_find(const char *haystack, const char *needle);
1653
1668bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end);
1669
1684const char *str_rchr(const char *haystack, char needle);
1685
1700int str_countchr(const char *haystack, char needle);
1701
1712void str_hex(char *dst, int dst_size, const void *data, int data_size);
1713
1728void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line = 12);
1729
1730/*
1731 Function: str_hex_decode
1732 Takes a hex string *without spaces between bytes* and returns a
1733 byte array.
1734
1735 Parameters:
1736 dst - Buffer for the byte array
1737 dst_size - size of the buffer
1738 data - String to decode
1739
1740 Returns:
1741 2 - String doesn't exactly fit the buffer
1742 1 - Invalid character in string
1743 0 - Success
1744
1745 Remarks:
1746 - The contents of the buffer is only valid on success
1747*/
1748int str_hex_decode(void *dst, int dst_size, const char *src);
1749
1750/*
1751 Function: str_base64
1752 Takes a datablock and generates the base64 encoding of it.
1753
1754 Parameters:
1755 dst - Buffer to fill with base64 data
1756 dst_size - Size of the buffer
1757 data - Data to turn into base64
1758 data - Size of the data
1759
1760 Remarks:
1761 - The destination buffer will be zero-terminated
1762*/
1763void str_base64(char *dst, int dst_size, const void *data, int data_size);
1764
1765/*
1766 Function: str_base64_decode
1767 Takes a base64 string without any whitespace and correct
1768 padding and returns a byte array.
1769
1770 Parameters:
1771 dst - Buffer for the byte array
1772 dst_size - Size of the buffer
1773 data - String to decode
1774
1775 Returns:
1776 <0 - Error
1777 >= 0 - Success, length of the resulting byte buffer
1778
1779 Remarks:
1780 - The contents of the buffer is only valid on success
1781*/
1782int str_base64_decode(void *dst, int dst_size, const char *data);
1783
1784/*
1785 Function: str_timestamp
1786 Copies a time stamp in the format year-month-day_hour-minute-second to the string.
1787
1788 Parameters:
1789 buffer - Pointer to a buffer that shall receive the time stamp string.
1790 buffer_size - Size of the buffer.
1791
1792 Remarks:
1793 - Guarantees that buffer string will contain zero-termination.
1794*/
1795void str_timestamp(char *buffer, int buffer_size);
1796void str_timestamp_format(char *buffer, int buffer_size, const char *format)
1797 GNUC_ATTRIBUTE((format(strftime, 3, 0)));
1798void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
1799 GNUC_ATTRIBUTE((format(strftime, 4, 0)));
1800
1813bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
1814 GNUC_ATTRIBUTE((format(strftime, 2, 0)));
1815
1816#define FORMAT_TIME "%H:%M:%S"
1817#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
1818#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
1819
1820enum
1821{
1828};
1829
1830/*
1831 Function: str_times
1832 Formats a time string.
1833
1834 Parameters:
1835 centisecs - Time in centiseconds, minimum value clamped to 0
1836 format - Format of the time string, see enum above, for example TIME_DAYS
1837 buffer - Pointer to a buffer that shall receive the time stamp string.
1838 buffer_size - Size of the buffer.
1839
1840 Returns:
1841 Number of bytes written, -1 on invalid format or buffer_size <= 0
1842
1843 Remarks:
1844 - Guarantees that buffer string will contain zero-termination, assuming
1845 buffer_size > 0.
1846*/
1847int str_time(int64_t centisecs, int format, char *buffer, int buffer_size);
1848int str_time_float(float secs, int format, char *buffer, int buffer_size);
1849
1850/*
1851 Function: str_escape
1852 Escapes \ and " characters in a string.
1853
1854 Parameters:
1855 dst - Destination array pointer, gets increased, will point to
1856 the terminating null.
1857 src - Source array
1858 end - End of destination array
1859*/
1860void str_escape(char **dst, const char *src, const char *end);
1861
1880void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
1881
1894void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user);
1895
1910int fs_makedir(const char *path);
1911
1925int fs_removedir(const char *path);
1926
1938int fs_makedir_rec_for(const char *path);
1939
1957int fs_storage_path(const char *appname, char *path, int max);
1958
1971int fs_is_file(const char *path);
1972
1985int fs_is_dir(const char *path);
1986
1998int fs_is_relative_path(const char *path);
1999
2011int fs_chdir(const char *path);
2012
2025char *fs_getcwd(char *buffer, int buffer_size);
2026
2041const char *fs_filename(const char *path);
2042
2058void fs_split_file_extension(const char *filename, char *name, size_t name_size, char *extension = nullptr, size_t extension_size = 0);
2059
2071int fs_parent_dir(char *path);
2072
2085int fs_remove(const char *filename);
2086
2099int fs_rename(const char *oldname, const char *newname);
2100
2115int fs_file_time(const char *name, time_t *created, time_t *modified);
2116
2117/*
2118 Group: Undocumented
2119*/
2120
2121/*
2122 Function: net_tcp_connect_non_blocking
2123
2124 DOCTODO: serp
2125*/
2127
2128/*
2129 Function: net_set_non_blocking
2130
2131 DOCTODO: serp
2132*/
2134
2135/*
2136 Function: net_set_non_blocking
2137
2138 DOCTODO: serp
2139*/
2140int net_set_blocking(NETSOCKET sock);
2141
2142/*
2143 Function: net_errno
2144
2145 DOCTODO: serp
2146*/
2147int net_errno();
2148
2149/*
2150 Function: net_would_block
2151
2152 DOCTODO: serp
2153*/
2154int net_would_block();
2155
2156int net_socket_read_wait(NETSOCKET sock, int time);
2157
2167void swap_endian(void *data, unsigned elem_size, unsigned num);
2168
2169typedef struct
2170{
2172 uint64_t sent_bytes;
2174 uint64_t recv_bytes;
2175} NETSTATS;
2176
2177void net_stats(NETSTATS *stats);
2178
2179int str_toint(const char *str);
2180bool str_toint(const char *str, int *out);
2181int str_toint_base(const char *str, int base);
2182unsigned long str_toulong_base(const char *str, int base);
2183int64_t str_toint64_base(const char *str, int base = 10);
2184float str_tofloat(const char *str);
2185bool str_tofloat(const char *str, float *out);
2186
2198int str_isspace(char c);
2199
2200char str_uppercase(char c);
2201
2202bool str_isnum(char c);
2203
2204int str_isallnum(const char *str);
2205
2206int str_isallnum_hex(const char *str);
2207
2208unsigned str_quickhash(const char *str);
2209
2210int str_utf8_to_skeleton(const char *str, int *buf, int buf_len);
2211
2212/*
2213 Function: str_utf8_comp_confusable
2214 Compares two strings for visual appearance.
2215
2216 Parameters:
2217 str1 - String to compare.
2218 str2 - String to compare.
2219
2220 Returns:
2221 0 if the strings are confusable.
2222 !=0 otherwise.
2223*/
2224int str_utf8_comp_confusable(const char *str1, const char *str2);
2225
2226/*
2227 Function: str_utf8_tolower
2228 Converts the given Unicode codepoint to lowercase (locale insensitive).
2229
2230 Parameters:
2231 code - Unicode codepoint to convert.
2232
2233 Returns:
2234 Lowercase codepoint
2235*/
2236int str_utf8_tolower(int code);
2237
2238/*
2239 Function: str_utf8_comp_nocase
2240 Compares two utf8 strings case insensitively.
2241
2242 Parameters:
2243 a - String to compare.
2244 b - String to compare.
2245
2246 Returns:
2247 <0 - String a is less than string b
2248 0 - String a is equal to string b
2249 >0 - String a is greater than string b
2250*/
2251int str_utf8_comp_nocase(const char *a, const char *b);
2252
2253/*
2254 Function: str_utf8_comp_nocase_num
2255 Compares up to num bytes of two utf8 strings case insensitively.
2256
2257 Parameters:
2258 a - String to compare.
2259 b - String to compare.
2260 num - Maximum bytes to compare
2261
2262 Returns:
2263 <0 - String a is less than string b
2264 0 - String a is equal to string b
2265 >0 - String a is greater than string b
2266*/
2267int str_utf8_comp_nocase_num(const char *a, const char *b, int num);
2268
2269/*
2270 Function: str_utf8_find_nocase
2271 Finds a utf8 string inside another utf8 string case insensitively.
2272
2273 Parameters:
2274 haystack - String to search in
2275 needle - String to search for
2276 end - A pointer that will be set to a pointer into haystack directly behind the
2277 last character where the needle was found. Will be set to nullptr if needle
2278 could not be found. Optional parameter.
2279
2280 Returns:
2281 A pointer into haystack where the needle was found.
2282 Returns NULL if needle could not be found.
2283
2284 Remarks:
2285 - The strings are treated as zero-terminated strings.
2286*/
2287const char *str_utf8_find_nocase(const char *haystack, const char *needle, const char **end = nullptr);
2288
2289/*
2290 Function: str_utf8_isspace
2291 Checks whether the given Unicode codepoint renders as space.
2292
2293 Parameters:
2294 code - Unicode codepoint to check.
2295
2296 Returns:
2297 0 if the codepoint does not render as space, != 0 if it does.
2298*/
2299int str_utf8_isspace(int code);
2300
2301int str_utf8_isstart(char c);
2302
2303/*
2304 Function: str_utf8_skip_whitespaces
2305 Skips leading characters that render as spaces.
2306
2307 Parameters:
2308 str - Pointer to the string.
2309
2310 Returns:
2311 Pointer to the first non-whitespace character found
2312 within the string.
2313
2314 Remarks:
2315 - The strings are treated as zero-terminated strings.
2316*/
2317const char *str_utf8_skip_whitespaces(const char *str);
2318
2319/*
2320 Function: str_utf8_trim_right
2321 Removes trailing characters that render as spaces by modifying
2322 the string in-place.
2323
2324 Parameters:
2325 param - Pointer to the string.
2326
2327 Remarks:
2328 - The strings are treated as zero-terminated strings.
2329 - The string is modified in-place.
2330*/
2331void str_utf8_trim_right(char *param);
2332
2333/*
2334 Function: str_utf8_rewind
2335 Moves a cursor backwards in an utf8 string
2336
2337 Parameters:
2338 str - utf8 string
2339 cursor - position in the string
2340
2341 Returns:
2342 New cursor position.
2343
2344 Remarks:
2345 - Won't move the cursor less then 0
2346*/
2347int str_utf8_rewind(const char *str, int cursor);
2348
2349/*
2350 Function: str_utf8_fix_truncation
2351 Fixes truncation of a Unicode character at the end of a UTF-8
2352 string.
2353
2354 Returns:
2355 The new string length.
2356
2357 Parameters:
2358 str - utf8 string
2359*/
2360int str_utf8_fix_truncation(char *str);
2361
2362/*
2363 Function: str_utf8_forward
2364 Moves a cursor forwards in an utf8 string
2365
2366 Parameters:
2367 str - utf8 string
2368 cursor - position in the string
2369
2370 Returns:
2371 New cursor position.
2372
2373 Remarks:
2374 - Won't move the cursor beyond the zero termination marker
2375*/
2376int str_utf8_forward(const char *str, int cursor);
2377
2378/*
2379 Function: str_utf8_decode
2380 Decodes a utf8 codepoint
2381
2382 Parameters:
2383 ptr - Pointer to a utf8 string. This pointer will be moved forward.
2384
2385 Returns:
2386 The Unicode codepoint. -1 for invalid input and 0 for end of string.
2387
2388 Remarks:
2389 - This function will also move the pointer forward.
2390 - You may call this function again after an error occurred.
2391*/
2392int str_utf8_decode(const char **ptr);
2393
2394/*
2395 Function: str_utf8_encode
2396 Encode an utf8 character
2397
2398 Parameters:
2399 ptr - Pointer to a buffer that should receive the data. Should be able to hold at least 4 bytes.
2400
2401 Returns:
2402 Number of bytes put into the buffer.
2403
2404 Remarks:
2405 - Does not do zero termination of the string.
2406*/
2407int str_utf8_encode(char *ptr, int chr);
2408
2409/*
2410 Function: str_utf8_check
2411 Checks if a strings contains just valid utf8 characters.
2412
2413 Parameters:
2414 str - Pointer to a possible utf8 string.
2415
2416 Returns:
2417 0 - invalid characters found.
2418 1 - only valid characters found.
2419
2420 Remarks:
2421 - The string is treated as zero-terminated utf8 string.
2422*/
2423int str_utf8_check(const char *str);
2424
2425/*
2426 Function: str_utf8_copy_num
2427 Copies a number of utf8 characters from one string to another.
2428
2429 Parameters:
2430 dst - Pointer to a buffer that shall receive the string.
2431 src - String to be copied.
2432 dst_size - Size of the buffer dst.
2433 num - maximum number of utf8 characters to be copied.
2434
2435 Remarks:
2436 - The strings are treated as zero-terminated strings.
2437 - Garantees that dst string will contain zero-termination.
2438*/
2439void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num);
2440
2441/*
2442 Function: str_utf8_stats
2443 Determines the byte size and utf8 character count of a utf8 string.
2444
2445 Parameters:
2446 str - Pointer to the string.
2447 max_size - Maximum number of bytes to count.
2448 max_count - Maximum number of utf8 characters to count.
2449 size - Pointer to store size (number of non-zero bytes) of the string.
2450 count - Pointer to store count of utf8 characters of the string.
2451
2452 Remarks:
2453 - The string is treated as zero-terminated utf8 string.
2454 - It's the user's responsibility to make sure the bounds are aligned.
2455*/
2456void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count);
2457
2469size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset);
2470
2482size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset);
2483
2484/*
2485 Function: str_next_token
2486 Writes the next token after str into buf, returns the rest of the string.
2487
2488 Parameters:
2489 str - Pointer to string.
2490 delim - Delimiter for tokenization.
2491 buffer - Buffer to store token in.
2492 buffer_size - Size of the buffer.
2493
2494 Returns:
2495 Pointer to rest of the string.
2496
2497 Remarks:
2498 - The token is always null-terminated.
2499*/
2500const char *str_next_token(const char *str, const char *delim, char *buffer, int buffer_size);
2501
2502/*
2503 Function: str_in_list
2504 Checks if needle is in list delimited by delim
2505
2506 Parameters:
2507 list - List
2508 delim - List delimiter.
2509 needle - Item that is being looked for.
2510
2511 Returns:
2512 1 - Item is in list.
2513 0 - Item isn't in list.
2514*/
2515int str_in_list(const char *list, const char *delim, const char *needle);
2516
2529unsigned bytes_be_to_uint(const unsigned char *bytes);
2530
2542void uint_to_bytes_be(unsigned char *bytes, unsigned value);
2543
2556int pid();
2557
2568void cmdline_fix(int *argc, const char ***argv);
2569
2578void cmdline_free(int argc, const char **argv);
2579
2580#if defined(CONF_FAMILY_WINDOWS)
2586typedef void *PROCESS;
2592constexpr PROCESS INVALID_PROCESS = nullptr;
2593#else
2599typedef pid_t PROCESS;
2606#endif
2607#if !defined(CONF_PLATFORM_ANDROID)
2617{
2621 FOREGROUND,
2622
2626 BACKGROUND,
2627};
2628
2639PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state);
2640
2650int kill_process(PROCESS process);
2651
2662bool is_process_alive(PROCESS process);
2663
2676int open_link(const char *link);
2677
2690int open_file(const char *path);
2691#endif // !defined(CONF_PLATFORM_ANDROID)
2692
2708void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length);
2709
2718[[nodiscard]] int secure_random_init();
2719
2728
2741void secure_random_password(char *buffer, unsigned length, unsigned pw_length);
2742
2751void secure_random_fill(void *bytes, unsigned length);
2752
2762int secure_rand();
2763
2774int secure_rand_below(int below);
2775
2786bool os_version_str(char *version, size_t length);
2787
2802void os_locale_str(char *locale, size_t length);
2803
2804#if defined(CONF_EXCEPTION_HANDLING)
2815void init_exception_handler();
2816
2824void set_exception_handler_log_file(const char *log_file_path);
2825#endif
2826
2834std::chrono::nanoseconds time_get_nanoseconds();
2835
2836int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds);
2837
2845{
2847 const char **m_ppArgv;
2848
2849public:
2850 CCmdlineFix(int *pArgc, const char ***pppArgv)
2851 {
2852 cmdline_fix(pArgc, pppArgv);
2853 m_Argc = *pArgc;
2854 m_ppArgv = *pppArgv;
2855 }
2857 {
2859 }
2860};
2861
2862#if defined(CONF_FAMILY_WINDOWS)
2876std::wstring windows_utf8_to_wide(const char *str);
2877
2891std::optional<std::string> windows_wide_to_utf8(const wchar_t *wide_str);
2892
2903class CWindowsComLifecycle
2904{
2905public:
2906 CWindowsComLifecycle(bool HasWindow);
2907 ~CWindowsComLifecycle();
2908};
2909
2923bool shell_register_protocol(const char *protocol_name, const char *executable, bool *updated);
2924
2940bool shell_register_extension(const char *extension, const char *description, const char *executable_name, const char *executable, bool *updated);
2941
2955bool shell_register_application(const char *name, const char *executable, bool *updated);
2956
2971bool shell_unregister_class(const char *shell_class, bool *updated);
2972
2985bool shell_unregister_application(const char *executable, bool *updated);
2986
2994void shell_update();
2995#endif
2996
2997template<>
2998struct std::hash<NETADDR>
2999{
3000 size_t operator()(const NETADDR &Addr) const noexcept;
3001};
3002
3003#endif
Definition: system.h:2845
~CCmdlineFix()
Definition: system.h:2856
int m_Argc
Definition: system.h:2846
const char ** m_ppArgv
Definition: system.h:2847
CCmdlineFix(int *pArgc, const char ***pppArgv)
Definition: system.h:2850
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:700
IOHANDLE io_current_exe()
Definition: system.cpp:411
void aio_wait(ASYNCIO *aio)
Definition: system.cpp:731
int io_skip(IOHANDLE io, int size)
Definition: system.cpp:314
void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:643
void io_read_all(IOHANDLE io, void **result, unsigned *result_len)
Definition: system.cpp:269
int io_flush(IOHANDLE io)
Definition: system.cpp:373
IOHANDLE io_stderr()
Definition: system.cpp:406
int io_seek(IOHANDLE io, int offset, int origin)
Definition: system.cpp:319
IOHANDLE io_open(const char *filename, int flags)
Definition: system.cpp:202
int io_close(IOHANDLE io)
Definition: system.cpp:368
char * io_read_all_str(IOHANDLE io)
Definition: system.cpp:301
void aio_write(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:693
void aio_write_newline(ASYNCIO *aio)
Definition: system.cpp:709
int aio_error(ASYNCIO *aio)
Definition: system.cpp:716
void aio_free(ASYNCIO *aio)
Definition: system.cpp:747
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size)
Definition: system.cpp:354
bool io_write_newline(IOHANDLE io)
Definition: system.cpp:359
void aio_lock(ASYNCIO *aio)
Definition: system.cpp:632
void aio_close(ASYNCIO *aio)
Definition: system.cpp:722
int io_sync(IOHANDLE io)
Definition: system.cpp:378
IOHANDLE io_stdin()
Definition: system.cpp:396
int io_error(IOHANDLE io)
Definition: system.cpp:391
long int io_length(IOHANDLE io)
Definition: system.cpp:345
IOHANDLE io_stdout()
Definition: system.cpp:401
ASYNCIO * aio_new(IOHANDLE io)
Definition: system.cpp:575
void aio_unlock(ASYNCIO *aio)
Definition: system.cpp:637
unsigned io_read(IOHANDLE io, void *buffer, unsigned size)
Definition: system.cpp:264
long int io_tell(IOHANDLE io)
Definition: system.cpp:340
@ IOSEEK_END
Definition: system.h:258
@ IOSEEK_CUR
Definition: system.h:252
@ IOFLAG_APPEND
Definition: system.h:239
@ IOFLAG_WRITE
Definition: system.h:233
@ IOFLAG_READ
Definition: system.h:227
@ IOSEEK_START
Definition: system.h:246
void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user)
Definition: system.cpp:2105
const char * fs_filename(const char *path)
Definition: system.cpp:2422
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:2432
int fs_is_relative_path(const char *path)
Definition: system.cpp:2377
int fs_is_file(const char *path)
Definition: system.cpp:2349
int fs_removedir(const char *path)
Definition: system.cpp:2335
int fs_parent_dir(char *path)
Definition: system.cpp:2455
void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user)
Definition: system.cpp:2157
char * fs_getcwd(char *buffer, int buffer_size)
Definition: system.cpp:2397
int fs_is_dir(const char *path)
Definition: system.cpp:2363
int fs_file_time(const char *name, time_t *created, time_t *modified)
Definition: system.cpp:2496
int fs_makedir_rec_for(const char *path)
Definition: system.cpp:2291
int fs_storage_path(const char *appname, char *path, int max)
Definition: system.cpp:2224
int fs_chdir(const char *path)
Definition: system.cpp:2387
int fs_remove(const char *filename)
Definition: system.cpp:2472
int fs_rename(const char *oldname, const char *newname)
Definition: system.cpp:2482
int fs_makedir(const char *path)
Definition: system.cpp:2312
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:794
bool net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port)
Definition: system.cpp:1106
int net_addr_comp_noport(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1031
void net_init()
Definition: system.cpp:2057
int net_addr_comp(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1021
struct sockaddr_un UNIXSOCKETADDR
Definition: system.h:798
int net_tcp_close(NETSOCKET sock)
Definition: system.cpp:2034
int net_tcp_listen(NETSOCKET sock, int backlog)
Definition: system.cpp:1919
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr)
Definition: system.cpp:1929
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr)
Definition: system.cpp:1976
NETSOCKET net_tcp_create(NETADDR bindaddr)
Definition: system.cpp:1842
int net_tcp_send(NETSOCKET sock, const void *data, int size)
Definition: system.cpp:2010
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize)
Definition: system.cpp:2022
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size)
Definition: system.cpp:1634
int net_udp_close(NETSOCKET sock)
Definition: system.cpp:1837
int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size)
Definition: system.cpp:2071
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path)
Definition: system.cpp:2076
UNIXSOCKET net_unix_create_unnamed()
Definition: system.cpp:2066
void net_unix_close(UNIXSOCKET sock)
Definition: system.cpp:2083
void secure_random_password(char *buffer, unsigned length, unsigned pw_length)
Definition: system.cpp:4390
void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length)
Definition: system.cpp:4370
int secure_rand()
Definition: system.cpp:4430
int secure_random_init()
Definition: system.cpp:4311
int secure_random_uninit()
Definition: system.cpp:4341
void secure_random_fill(void *bytes, unsigned length)
Definition: system.cpp:4406
int secure_rand_below(int below)
Definition: system.cpp:4449
void sphore_signal(SEMAPHORE *sem)
Definition: system.cpp:914
void sphore_destroy(SEMAPHORE *sem)
Definition: system.cpp:918
void sphore_init(SEMAPHORE *sem)
Definition: system.cpp:901
void sphore_wait(SEMAPHORE *sem)
Definition: system.cpp:905
bool os_version_str(char *version, size_t length)
Definition: system.cpp:4465
int kill_process(PROCESS process)
Definition: system.cpp:4203
bool is_process_alive(PROCESS process)
Definition: system.cpp:4223
EShellExecuteWindowState
Definition: system.h:2617
int open_link(const char *link)
Definition: system.cpp:4236
constexpr PROCESS INVALID_PROCESS
Definition: system.h:2605
void cmdline_free(int argc, const char **argv)
Definition: system.cpp:4145
void os_locale_str(char *locale, size_t length)
Definition: system.cpp:4544
void cmdline_fix(int *argc, const char ***argv)
Definition: system.cpp:4107
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state)
Definition: system.cpp:4154
int open_file(const char *path)
Definition: system.cpp:4276
int pid()
Definition: system.cpp:4098
pid_t PROCESS
Definition: system.h:2599
const char * str_rchr(const char *haystack, char needle)
Definition: system.cpp:3197
char * str_skip_to_whitespace(char *str)
Definition: system.cpp:2886
int str_length(const char *str)
Definition: system.cpp:2754
void str_sanitize(char *str)
Definition: system.cpp:2832
const char * str_startswith(const char *str, const char *prefix)
Definition: system.cpp:2988
bool str_has_cc(const char *str)
Definition: system.cpp:2805
void str_sanitize_cc(char *str)
Definition: system.cpp:2820
const char * str_skip_whitespaces_const(const char *str)
Definition: system.cpp:2907
const char * str_skip_to_whitespace_const(const char *str)
Definition: system.cpp:2893
int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
Definition: system.cpp:2759
int str_comp_num(const char *a, const char *b, int num)
Definition: system.cpp:2938
void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2727
int str_comp_filenames(const char *a, const char *b)
Definition: system.cpp:2943
int str_comp_nocase(const char *a, const char *b)
Definition: system.cpp:2915
void str_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2744
bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end)
Definition: system.cpp:3165
int str_countchr(const char *haystack, char needle)
Definition: system.cpp:3202
int str_comp(const char *a, const char *b)
Definition: system.cpp:2933
void str_append(char *dst, const char *src, int dst_size)
Definition: system.cpp:2703
void str_clean_whitespaces(char *str)
Definition: system.cpp:2855
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2720
char * str_skip_whitespaces(char *str)
Definition: system.cpp:2900
int str_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:2924
int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len)
Definition: system.cpp:3107
int str_isspace(char c)
Definition: system.cpp:3582
const char * str_trim_words(const char *str, int words)
Definition: system.cpp:2792
void thread_wait(void *thread)
Definition: system.cpp:809
void * thread_init(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:783
void thread_yield()
Definition: system.cpp:821
void thread_init_and_detach(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:843
void thread_detach(void *thread)
Definition: system.cpp:832
std::chrono::nanoseconds time_get_nanoseconds()
Definition: system.cpp:4660
ETimeSeason
Definition: system.h:758
void set_new_tick()
Definition: system.cpp:926
int64_t time_freq()
Definition: system.cpp:953
int time_houroftheday()
Definition: system.cpp:2618
int64_t time_timestamp()
Definition: system.cpp:2600
ETimeSeason time_season()
Definition: system.cpp:2656
int64_t time_get()
Definition: system.cpp:941
int64_t time_get_impl()
Definition: system.cpp:936
@ SEASON_AUTUMN
Definition: system.h:761
@ SEASON_WINTER
Definition: system.h:762
@ SEASON_SPRING
Definition: system.h:759
@ SEASON_HALLOWEEN
Definition: system.h:764
@ SEASON_XMAS
Definition: system.h:765
@ SEASON_EASTER
Definition: system.h:763
@ SEASON_SUMMER
Definition: system.h:760
@ SEASON_NEWYEAR
Definition: system.h:766
void * IOHANDLE
Definition: logger.h:11
Definition: system.cpp:452
void * thread
Definition: system.cpp:456
unsigned char * buffer
Definition: system.cpp:458
IOHANDLE io
Definition: system.cpp:454
Definition: types.h:67
Definition: system.cpp:110
Definition: system.h:2170
uint64_t recv_packets
Definition: system.h:2173
uint64_t recv_bytes
Definition: system.h:2174
uint64_t sent_packets
Definition: system.h:2171
uint64_t sent_bytes
Definition: system.h:2172
void str_utf8_trim_right(char *param)
Definition: system.cpp:3768
void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line=12)
Definition: system.cpp:3229
int str_utf8_comp_nocase(const char *a, const char *b)
Definition: system.cpp:3670
void swap_endian(void *data, unsigned elem_size, unsigned num)
Definition: system.cpp:2522
size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset)
Definition: system.cpp:4016
void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num)
Definition: system.cpp:3963
NETSOCKET net_udp_create(NETADDR bindaddr)
Definition: system.cpp:1536
void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler)
Definition: system.cpp:159
int str_isallnum(const char *str)
Definition: system.cpp:3599
int str_utf8_forward(const char *str, int cursor)
Definition: system.cpp:3828
const char * str_next_token(const char *str, const char *delim, char *buffer, int buffer_size)
Definition: system.cpp:4065
int str_utf8_decode(const char **ptr)
Definition: system.cpp:3883
unsigned long str_toulong_base(const char *str, int base)
Definition: system.cpp:3643
const char * str_find_nocase(const char *haystack, const char *needle)
Definition: system.cpp:3127
int net_would_block()
Definition: system.cpp:2048
void str_base64(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3321
int net_host_lookup(const char *hostname, NETADDR *addr, int types)
Definition: system.cpp:1211
int str_utf8_encode(char *ptr, int chr)
Definition: system.cpp:3838
int str_utf8_dist(const char *a, const char *b)
Definition: system.cpp:3051
int str_toint_base(const char *str, int base)
Definition: system.cpp:3638
int str_utf8_isstart(char c)
Definition: system.cpp:3793
bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
Definition: system.cpp:3490
void str_escape(char **dst, const char *src, const char *end)
Definition: system.cpp:3561
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
Definition: system.cpp:1285
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:3071
const char * str_utf8_skip_whitespaces(const char *str)
Definition: system.cpp:3748
void str_sanitize_filename(char *str)
Definition: system.cpp:2843
int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr)
Definition: system.cpp:1999
std::function< void(const char *message)> DBG_ASSERT_HANDLER
Definition: system.h:116
int net_set_non_blocking(NETSOCKET sock)
Definition: system.cpp:1909
int str_in_list(const char *list, const char *delim, const char *needle)
Definition: system.cpp:4051
int str_utf8_comp_confusable(const char *str1, const char *str2)
Definition: confusables.cpp:83
int net_socket_type(NETSOCKET sock)
Definition: system.cpp:1531
void str_timestamp(char *buffer, int buffer_size)
Definition: system.cpp:3485
void uint_to_bytes_be(unsigned char *bytes, unsigned value)
Definition: system.cpp:4090
int str_format_int(char *buffer, size_t buffer_size, int value)
Definition: system.cpp:2771
int str_base64_decode(void *dst, int dst_size, const char *data)
Definition: system.cpp:3398
int str_time_float(float secs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3556
const NETADDR NETADDR_ZEROED
Definition: system.cpp:961
#define GNUC_ATTRIBUTE(x)
Definition: system.h:88
int net_errno()
Definition: system.cpp:2039
int str_toint(const char *str)
Definition: system.cpp:3621
void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count)
Definition: system.cpp:3981
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
Definition: system.h:1280
int str_hex_decode(void *dst, int dst_size, const char *src)
Definition: system.cpp:3304
bool str_isnum(char c)
Definition: system.cpp:3594
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3478
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3471
float str_tofloat(const char *str)
Definition: system.cpp:3653
void str_hex(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3214
void net_stats(NETSTATS *stats)
Definition: system.cpp:3577
unsigned str_quickhash(const char *str)
Definition: system.cpp:4029
int net_socket_read_wait(NETSOCKET sock, int time)
Definition: system.cpp:2548
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:1914
sem_t SEMAPHORE
Definition: system.h:669
size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset)
Definition: system.cpp:4001
int net_addr_from_str(NETADDR *addr, const char *string)
Definition: system.cpp:1334
int str_utf8_check(const char *str)
Definition: system.cpp:3950
const char * str_utf8_find_nocase(const char *haystack, const char *needle, const char **end=nullptr)
Definition: system.cpp:3710
#define str_format
Definition: system.h:1299
int str_isallnum_hex(const char *str)
Definition: system.cpp:3610
int str_utf8_isspace(int code)
Definition: system.cpp:3737
int str_time(int64_t centisecs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3509
const char * str_startswith_nocase(const char *str, const char *prefix)
Definition: system.cpp:2975
int str_utf8_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:3686
const char * str_endswith_nocase(const char *str, const char *suffix)
Definition: system.cpp:3001
unsigned bytes_be_to_uint(const unsigned char *bytes)
Definition: system.cpp:4085
int str_utf8_rewind(const char *str, int cursor)
Definition: system.cpp:3800
int str_utf8_fix_truncation(char *str)
Definition: system.cpp:3811
const char * str_endswith(const char *str, const char *suffix)
Definition: system.cpp:3021
const char * str_find(const char *haystack, const char *needle)
Definition: system.cpp:3146
char str_uppercase(char c)
Definition: system.cpp:3587
int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data)
Definition: system.cpp:1759
int64_t str_toint64_base(const char *str, int base=10)
Definition: system.cpp:3648
int str_utf8_tolower(int code)
Definition: tolower.cpp:12
@ TIME_SECS_CENTISECS
Definition: system.h:1827
@ TIME_HOURS_CENTISECS
Definition: system.h:1825
@ TIME_DAYS
Definition: system.h:1822
@ TIME_MINS
Definition: system.h:1824
@ TIME_HOURS
Definition: system.h:1823
@ TIME_MINS_CENTISECS
Definition: system.h:1826
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