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
872void net_addr_str(const NETADDR *addr, char *string, int max_length, bool add_port);
873
897int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size);
898
907int net_addr_from_str(NETADDR *addr, const char *string);
908
914/*
915 Function: net_socket_type
916 Determine a socket's type.
917
918 Parameters:
919 sock - Socket whose type should be determined.
920
921 Returns:
922 The socket type, a bitset of `NETTYPE_IPV4`, `NETTYPE_IPV6` and
923 `NETTYPE_WEBSOCKET_IPV4`.
924*/
925int net_socket_type(NETSOCKET sock);
926
927/*
928 Function: net_udp_create
929 Creates a UDP socket and binds it to a port.
930
931 Parameters:
932 bindaddr - Address to bind the socket to.
933
934 Returns:
935 On success it returns an handle to the socket. On failure it
936 returns NETSOCKET_INVALID.
937*/
939
953int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
954
955/*
956 Function: net_udp_recv
957 Receives a packet over an UDP socket.
958
959 Parameters:
960 sock - Socket to use.
961 addr - Pointer to an NETADDR that will receive the address.
962 data - Received data. Will be invalidated when this function is
963 called again.
964
965 Returns:
966 On success it returns the number of bytes received. Returns -1
967 on error.
968*/
969int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data);
970
980int net_udp_close(NETSOCKET sock);
981
997
1008int net_tcp_listen(NETSOCKET sock, int backlog);
1009
1021int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
1022
1034int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
1035
1047int net_tcp_send(NETSOCKET sock, const void *data, int size);
1048
1062int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
1063
1073int net_tcp_close(NETSOCKET sock);
1074
1075#if defined(CONF_FAMILY_UNIX)
1089
1102int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
1103
1112void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
1113
1121void net_unix_close(UNIXSOCKET sock);
1122
1123#elif defined(CONF_FAMILY_WINDOWS)
1124
1132std::string windows_format_system_message(unsigned long error);
1133
1134#endif
1135
1154void str_append(char *dst, const char *src, int dst_size);
1155
1167template<int N>
1168void str_append(char (&dst)[N], const char *src)
1169{
1170 str_append(dst, src, N);
1171}
1172
1187int str_copy(char *dst, const char *src, int dst_size);
1188
1200template<int N>
1201void str_copy(char (&dst)[N], const char *src)
1202{
1203 str_copy(dst, src, N);
1204}
1205
1219void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1220
1235void str_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1236
1246int str_length(const char *str);
1247
1264int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
1265 GNUC_ATTRIBUTE((format(printf, 3, 0)));
1266
1283int str_format(char *buffer, int buffer_size, const char *format, ...)
1284 GNUC_ATTRIBUTE((format(printf, 3, 4)));
1285
1286#if !defined(CONF_DEBUG)
1287int str_format_int(char *buffer, size_t buffer_size, int value);
1288
1289template<typename... Args>
1290int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
1291{
1292 static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
1293 return str_format(buffer, buffer_size, format, args...);
1294}
1295
1296template<>
1297inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
1298{
1299 if(strcmp(format, "%d") == 0)
1300 {
1301 return str_format_int(buffer, buffer_size, val);
1302 }
1303 else
1304 {
1305 return str_format(buffer, buffer_size, format, val);
1306 }
1307}
1308
1309#define str_format str_format_opt
1310#endif
1311
1325const char *str_trim_words(const char *str, int words);
1326
1338bool str_has_cc(const char *str);
1339
1349void str_sanitize_cc(char *str);
1350
1361void str_sanitize(char *str);
1362
1370void str_sanitize_filename(char *str);
1371
1381void str_clean_whitespaces(char *str);
1382
1396char *str_skip_to_whitespace(char *str);
1397
1402const char *str_skip_to_whitespace_const(const char *str);
1403
1417char *str_skip_whitespaces(char *str);
1418
1423const char *str_skip_whitespaces_const(const char *str);
1424
1440int str_comp_nocase(const char *a, const char *b);
1441
1459int str_comp_nocase_num(const char *a, const char *b, int num);
1460
1475int str_comp(const char *a, const char *b);
1476
1492int str_comp_num(const char *a, const char *b, int num);
1493
1508int str_comp_filenames(const char *a, const char *b);
1509
1510/*
1511 Function: str_startswith_nocase
1512 Checks case insensitive whether the string begins with a certain prefix.
1513
1514 Parameter:
1515 str - String to check.
1516 prefix - Prefix to look for.
1517
1518 Returns:
1519 A pointer to the string str after the string prefix, or 0 if
1520 the string prefix isn't a prefix of the string str.
1521
1522 Remarks:
1523 - The strings are treated as zero-terminated strings.
1524*/
1525const char *str_startswith_nocase(const char *str, const char *prefix);
1526
1540const char *str_startswith(const char *str, const char *prefix);
1541
1542/*
1543 Function: str_endswith_nocase
1544 Checks case insensitive whether the string ends with a certain suffix.
1545
1546 Parameter:
1547 str - String to check.
1548 suffix - Suffix to look for.
1549
1550 Returns:
1551 A pointer to the beginning of the suffix in the string str, or
1552 0 if the string suffix isn't a suffix of the string str.
1553
1554 Remarks:
1555 - The strings are treated as zero-terminated strings.
1556*/
1557const char *str_endswith_nocase(const char *str, const char *suffix);
1558
1559/*
1560 Function: str_endswith
1561 Checks case sensitive whether the string ends with a certain suffix.
1562
1563 Parameter:
1564 str - String to check.
1565 suffix - Suffix to look for.
1566
1567 Returns:
1568 A pointer to the beginning of the suffix in the string str, or
1569 0 if the string suffix isn't a suffix of the string str.
1570
1571 Remarks:
1572 - The strings are treated as zero-terminated strings.
1573*/
1574const char *str_endswith(const char *str, const char *suffix);
1575
1586int str_utf8_dist(const char *a, const char *b);
1587
1604int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len);
1605
1606/*
1607 Function: str_utf32_dist_buffer
1608 Computes the edit distance between two strings, allows buffers
1609 to be passed in.
1610
1611 Parameters:
1612 a - First string for the edit distance.
1613 a_len - Length of the first string.
1614 b - Second string for the edit distance.
1615 b_len - Length of the second string.
1616 buf - Buffer for the function.
1617 buf_len - Length of the buffer, must be at least as long as
1618 the length of both strings combined plus two.
1619
1620 Returns:
1621 The edit distance between the both strings.
1622
1623 Remarks:
1624 - The strings are treated as zero-terminated strings.
1625*/
1626int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len);
1627
1628/*
1629 Function: str_find_nocase
1630 Finds a string inside another string case insensitively.
1631
1632 Parameters:
1633 haystack - String to search in
1634 needle - String to search for
1635
1636 Returns:
1637 A pointer into haystack where the needle was found.
1638 Returns NULL if needle could not be found.
1639
1640 Remarks:
1641 - Only guaranteed to work with a-z/A-Z.
1642 (use str_utf8_find_nocase for unicode support)
1643 - The strings are treated as zero-terminated strings.
1644*/
1645const char *str_find_nocase(const char *haystack, const char *needle);
1646
1647/*
1648 Function: str_find
1649 Finds a string inside another string case sensitive.
1650
1651 Parameters:
1652 haystack - String to search in
1653 needle - String to search for
1654
1655 Returns:
1656 A pointer into haystack where the needle was found.
1657 Returns NULL if needle could not be found.
1658
1659 Remarks:
1660 - The strings are treated as zero-terminated strings.
1661*/
1662const char *str_find(const char *haystack, const char *needle);
1663
1678bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end);
1679
1694const char *str_rchr(const char *haystack, char needle);
1695
1710int str_countchr(const char *haystack, char needle);
1711
1722void str_hex(char *dst, int dst_size, const void *data, int data_size);
1723
1738void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line = 12);
1739
1740/*
1741 Function: str_hex_decode
1742 Takes a hex string *without spaces between bytes* and returns a
1743 byte array.
1744
1745 Parameters:
1746 dst - Buffer for the byte array
1747 dst_size - size of the buffer
1748 data - String to decode
1749
1750 Returns:
1751 2 - String doesn't exactly fit the buffer
1752 1 - Invalid character in string
1753 0 - Success
1754
1755 Remarks:
1756 - The contents of the buffer is only valid on success
1757*/
1758int str_hex_decode(void *dst, int dst_size, const char *src);
1759
1760/*
1761 Function: str_base64
1762 Takes a datablock and generates the base64 encoding of it.
1763
1764 Parameters:
1765 dst - Buffer to fill with base64 data
1766 dst_size - Size of the buffer
1767 data - Data to turn into base64
1768 data - Size of the data
1769
1770 Remarks:
1771 - The destination buffer will be zero-terminated
1772*/
1773void str_base64(char *dst, int dst_size, const void *data, int data_size);
1774
1775/*
1776 Function: str_base64_decode
1777 Takes a base64 string without any whitespace and correct
1778 padding and returns a byte array.
1779
1780 Parameters:
1781 dst - Buffer for the byte array
1782 dst_size - Size of the buffer
1783 data - String to decode
1784
1785 Returns:
1786 <0 - Error
1787 >= 0 - Success, length of the resulting byte buffer
1788
1789 Remarks:
1790 - The contents of the buffer is only valid on success
1791*/
1792int str_base64_decode(void *dst, int dst_size, const char *data);
1793
1794/*
1795 Function: str_timestamp
1796 Copies a time stamp in the format year-month-day_hour-minute-second to the string.
1797
1798 Parameters:
1799 buffer - Pointer to a buffer that shall receive the time stamp string.
1800 buffer_size - Size of the buffer.
1801
1802 Remarks:
1803 - Guarantees that buffer string will contain zero-termination.
1804*/
1805void str_timestamp(char *buffer, int buffer_size);
1806void str_timestamp_format(char *buffer, int buffer_size, const char *format)
1807 GNUC_ATTRIBUTE((format(strftime, 3, 0)));
1808void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
1809 GNUC_ATTRIBUTE((format(strftime, 4, 0)));
1810
1823bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
1824 GNUC_ATTRIBUTE((format(strftime, 2, 0)));
1825
1826#define FORMAT_TIME "%H:%M:%S"
1827#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
1828#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
1829
1830enum
1831{
1838};
1839
1840/*
1841 Function: str_times
1842 Formats a time string.
1843
1844 Parameters:
1845 centisecs - Time in centiseconds, minimum value clamped to 0
1846 format - Format of the time string, see enum above, for example TIME_DAYS
1847 buffer - Pointer to a buffer that shall receive the time stamp string.
1848 buffer_size - Size of the buffer.
1849
1850 Returns:
1851 Number of bytes written, -1 on invalid format or buffer_size <= 0
1852
1853 Remarks:
1854 - Guarantees that buffer string will contain zero-termination, assuming
1855 buffer_size > 0.
1856*/
1857int str_time(int64_t centisecs, int format, char *buffer, int buffer_size);
1858int str_time_float(float secs, int format, char *buffer, int buffer_size);
1859
1860/*
1861 Function: str_escape
1862 Escapes \ and " characters in a string.
1863
1864 Parameters:
1865 dst - Destination array pointer, gets increased, will point to
1866 the terminating null.
1867 src - Source array
1868 end - End of destination array
1869*/
1870void str_escape(char **dst, const char *src, const char *end);
1871
1890void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
1891
1904void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user);
1905
1920int fs_makedir(const char *path);
1921
1935int fs_removedir(const char *path);
1936
1948int fs_makedir_rec_for(const char *path);
1949
1967int fs_storage_path(const char *appname, char *path, int max);
1968
1981int fs_is_file(const char *path);
1982
1995int fs_is_dir(const char *path);
1996
2008int fs_is_relative_path(const char *path);
2009
2021int fs_chdir(const char *path);
2022
2035char *fs_getcwd(char *buffer, int buffer_size);
2036
2051const char *fs_filename(const char *path);
2052
2068void fs_split_file_extension(const char *filename, char *name, size_t name_size, char *extension = nullptr, size_t extension_size = 0);
2069
2081int fs_parent_dir(char *path);
2082
2095int fs_remove(const char *filename);
2096
2109int fs_rename(const char *oldname, const char *newname);
2110
2125int fs_file_time(const char *name, time_t *created, time_t *modified);
2126
2127/*
2128 Group: Undocumented
2129*/
2130
2131/*
2132 Function: net_tcp_connect_non_blocking
2133
2134 DOCTODO: serp
2135*/
2137
2138/*
2139 Function: net_set_non_blocking
2140
2141 DOCTODO: serp
2142*/
2144
2145/*
2146 Function: net_set_non_blocking
2147
2148 DOCTODO: serp
2149*/
2150int net_set_blocking(NETSOCKET sock);
2151
2152/*
2153 Function: net_errno
2154
2155 DOCTODO: serp
2156*/
2157int net_errno();
2158
2159/*
2160 Function: net_would_block
2161
2162 DOCTODO: serp
2163*/
2164int net_would_block();
2165
2166int net_socket_read_wait(NETSOCKET sock, int time);
2167
2177void swap_endian(void *data, unsigned elem_size, unsigned num);
2178
2179typedef struct
2180{
2182 uint64_t sent_bytes;
2184 uint64_t recv_bytes;
2185} NETSTATS;
2186
2187void net_stats(NETSTATS *stats);
2188
2189int str_toint(const char *str);
2190bool str_toint(const char *str, int *out);
2191int str_toint_base(const char *str, int base);
2192unsigned long str_toulong_base(const char *str, int base);
2193int64_t str_toint64_base(const char *str, int base = 10);
2194float str_tofloat(const char *str);
2195bool str_tofloat(const char *str, float *out);
2196
2208int str_isspace(char c);
2209
2210char str_uppercase(char c);
2211
2212bool str_isnum(char c);
2213
2214int str_isallnum(const char *str);
2215
2216int str_isallnum_hex(const char *str);
2217
2218unsigned str_quickhash(const char *str);
2219
2220int str_utf8_to_skeleton(const char *str, int *buf, int buf_len);
2221
2222/*
2223 Function: str_utf8_comp_confusable
2224 Compares two strings for visual appearance.
2225
2226 Parameters:
2227 str1 - String to compare.
2228 str2 - String to compare.
2229
2230 Returns:
2231 0 if the strings are confusable.
2232 !=0 otherwise.
2233*/
2234int str_utf8_comp_confusable(const char *str1, const char *str2);
2235
2236/*
2237 Function: str_utf8_tolower
2238 Converts the given Unicode codepoint to lowercase (locale insensitive).
2239
2240 Parameters:
2241 code - Unicode codepoint to convert.
2242
2243 Returns:
2244 Lowercase codepoint
2245*/
2246int str_utf8_tolower(int code);
2247
2248/*
2249 Function: str_utf8_comp_nocase
2250 Compares two utf8 strings case insensitively.
2251
2252 Parameters:
2253 a - String to compare.
2254 b - String to compare.
2255
2256 Returns:
2257 <0 - String a is less than string b
2258 0 - String a is equal to string b
2259 >0 - String a is greater than string b
2260*/
2261int str_utf8_comp_nocase(const char *a, const char *b);
2262
2263/*
2264 Function: str_utf8_comp_nocase_num
2265 Compares up to num bytes of two utf8 strings case insensitively.
2266
2267 Parameters:
2268 a - String to compare.
2269 b - String to compare.
2270 num - Maximum bytes to compare
2271
2272 Returns:
2273 <0 - String a is less than string b
2274 0 - String a is equal to string b
2275 >0 - String a is greater than string b
2276*/
2277int str_utf8_comp_nocase_num(const char *a, const char *b, int num);
2278
2279/*
2280 Function: str_utf8_find_nocase
2281 Finds a utf8 string inside another utf8 string case insensitively.
2282
2283 Parameters:
2284 haystack - String to search in
2285 needle - String to search for
2286 end - A pointer that will be set to a pointer into haystack directly behind the
2287 last character where the needle was found. Will be set to nullptr if needle
2288 could not be found. Optional parameter.
2289
2290 Returns:
2291 A pointer into haystack where the needle was found.
2292 Returns NULL if needle could not be found.
2293
2294 Remarks:
2295 - The strings are treated as zero-terminated strings.
2296*/
2297const char *str_utf8_find_nocase(const char *haystack, const char *needle, const char **end = nullptr);
2298
2299/*
2300 Function: str_utf8_isspace
2301 Checks whether the given Unicode codepoint renders as space.
2302
2303 Parameters:
2304 code - Unicode codepoint to check.
2305
2306 Returns:
2307 0 if the codepoint does not render as space, != 0 if it does.
2308*/
2309int str_utf8_isspace(int code);
2310
2311int str_utf8_isstart(char c);
2312
2313/*
2314 Function: str_utf8_skip_whitespaces
2315 Skips leading characters that render as spaces.
2316
2317 Parameters:
2318 str - Pointer to the string.
2319
2320 Returns:
2321 Pointer to the first non-whitespace character found
2322 within the string.
2323
2324 Remarks:
2325 - The strings are treated as zero-terminated strings.
2326*/
2327const char *str_utf8_skip_whitespaces(const char *str);
2328
2329/*
2330 Function: str_utf8_trim_right
2331 Removes trailing characters that render as spaces by modifying
2332 the string in-place.
2333
2334 Parameters:
2335 param - Pointer to the string.
2336
2337 Remarks:
2338 - The strings are treated as zero-terminated strings.
2339 - The string is modified in-place.
2340*/
2341void str_utf8_trim_right(char *param);
2342
2343/*
2344 Function: str_utf8_rewind
2345 Moves a cursor backwards in an utf8 string
2346
2347 Parameters:
2348 str - utf8 string
2349 cursor - position in the string
2350
2351 Returns:
2352 New cursor position.
2353
2354 Remarks:
2355 - Won't move the cursor less then 0
2356*/
2357int str_utf8_rewind(const char *str, int cursor);
2358
2359/*
2360 Function: str_utf8_fix_truncation
2361 Fixes truncation of a Unicode character at the end of a UTF-8
2362 string.
2363
2364 Returns:
2365 The new string length.
2366
2367 Parameters:
2368 str - utf8 string
2369*/
2370int str_utf8_fix_truncation(char *str);
2371
2372/*
2373 Function: str_utf8_forward
2374 Moves a cursor forwards in an utf8 string
2375
2376 Parameters:
2377 str - utf8 string
2378 cursor - position in the string
2379
2380 Returns:
2381 New cursor position.
2382
2383 Remarks:
2384 - Won't move the cursor beyond the zero termination marker
2385*/
2386int str_utf8_forward(const char *str, int cursor);
2387
2388/*
2389 Function: str_utf8_decode
2390 Decodes a utf8 codepoint
2391
2392 Parameters:
2393 ptr - Pointer to a utf8 string. This pointer will be moved forward.
2394
2395 Returns:
2396 The Unicode codepoint. -1 for invalid input and 0 for end of string.
2397
2398 Remarks:
2399 - This function will also move the pointer forward.
2400 - You may call this function again after an error occurred.
2401*/
2402int str_utf8_decode(const char **ptr);
2403
2404/*
2405 Function: str_utf8_encode
2406 Encode an utf8 character
2407
2408 Parameters:
2409 ptr - Pointer to a buffer that should receive the data. Should be able to hold at least 4 bytes.
2410
2411 Returns:
2412 Number of bytes put into the buffer.
2413
2414 Remarks:
2415 - Does not do zero termination of the string.
2416*/
2417int str_utf8_encode(char *ptr, int chr);
2418
2419/*
2420 Function: str_utf8_check
2421 Checks if a strings contains just valid utf8 characters.
2422
2423 Parameters:
2424 str - Pointer to a possible utf8 string.
2425
2426 Returns:
2427 0 - invalid characters found.
2428 1 - only valid characters found.
2429
2430 Remarks:
2431 - The string is treated as zero-terminated utf8 string.
2432*/
2433int str_utf8_check(const char *str);
2434
2435/*
2436 Function: str_utf8_copy_num
2437 Copies a number of utf8 characters from one string to another.
2438
2439 Parameters:
2440 dst - Pointer to a buffer that shall receive the string.
2441 src - String to be copied.
2442 dst_size - Size of the buffer dst.
2443 num - maximum number of utf8 characters to be copied.
2444
2445 Remarks:
2446 - The strings are treated as zero-terminated strings.
2447 - Garantees that dst string will contain zero-termination.
2448*/
2449void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num);
2450
2451/*
2452 Function: str_utf8_stats
2453 Determines the byte size and utf8 character count of a utf8 string.
2454
2455 Parameters:
2456 str - Pointer to the string.
2457 max_size - Maximum number of bytes to count.
2458 max_count - Maximum number of utf8 characters to count.
2459 size - Pointer to store size (number of non-zero bytes) of the string.
2460 count - Pointer to store count of utf8 characters of the string.
2461
2462 Remarks:
2463 - The string is treated as zero-terminated utf8 string.
2464 - It's the user's responsibility to make sure the bounds are aligned.
2465*/
2466void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count);
2467
2479size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset);
2480
2492size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset);
2493
2494/*
2495 Function: str_next_token
2496 Writes the next token after str into buf, returns the rest of the string.
2497
2498 Parameters:
2499 str - Pointer to string.
2500 delim - Delimiter for tokenization.
2501 buffer - Buffer to store token in.
2502 buffer_size - Size of the buffer.
2503
2504 Returns:
2505 Pointer to rest of the string.
2506
2507 Remarks:
2508 - The token is always null-terminated.
2509*/
2510const char *str_next_token(const char *str, const char *delim, char *buffer, int buffer_size);
2511
2512/*
2513 Function: str_in_list
2514 Checks if needle is in list delimited by delim
2515
2516 Parameters:
2517 list - List
2518 delim - List delimiter.
2519 needle - Item that is being looked for.
2520
2521 Returns:
2522 1 - Item is in list.
2523 0 - Item isn't in list.
2524*/
2525int str_in_list(const char *list, const char *delim, const char *needle);
2526
2539unsigned bytes_be_to_uint(const unsigned char *bytes);
2540
2552void uint_to_bytes_be(unsigned char *bytes, unsigned value);
2553
2566int pid();
2567
2578void cmdline_fix(int *argc, const char ***argv);
2579
2588void cmdline_free(int argc, const char **argv);
2589
2590#if defined(CONF_FAMILY_WINDOWS)
2596typedef void *PROCESS;
2602constexpr PROCESS INVALID_PROCESS = nullptr;
2603#else
2609typedef pid_t PROCESS;
2616#endif
2617#if !defined(CONF_PLATFORM_ANDROID)
2627{
2631 FOREGROUND,
2632
2636 BACKGROUND,
2637};
2638
2649PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state);
2650
2660int kill_process(PROCESS process);
2661
2672bool is_process_alive(PROCESS process);
2673
2686int open_link(const char *link);
2687
2700int open_file(const char *path);
2701#endif // !defined(CONF_PLATFORM_ANDROID)
2702
2718void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length);
2719
2728[[nodiscard]] int secure_random_init();
2729
2738
2751void secure_random_password(char *buffer, unsigned length, unsigned pw_length);
2752
2761void secure_random_fill(void *bytes, unsigned length);
2762
2772int secure_rand();
2773
2784int secure_rand_below(int below);
2785
2796bool os_version_str(char *version, size_t length);
2797
2812void os_locale_str(char *locale, size_t length);
2813
2814#if defined(CONF_EXCEPTION_HANDLING)
2825void init_exception_handler();
2826
2834void set_exception_handler_log_file(const char *log_file_path);
2835#endif
2836
2844std::chrono::nanoseconds time_get_nanoseconds();
2845
2846int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds);
2847
2855{
2857 const char **m_ppArgv;
2858
2859public:
2860 CCmdlineFix(int *pArgc, const char ***pppArgv)
2861 {
2862 cmdline_fix(pArgc, pppArgv);
2863 m_Argc = *pArgc;
2864 m_ppArgv = *pppArgv;
2865 }
2867 {
2869 }
2870};
2871
2872#if defined(CONF_FAMILY_WINDOWS)
2886std::wstring windows_utf8_to_wide(const char *str);
2887
2901std::optional<std::string> windows_wide_to_utf8(const wchar_t *wide_str);
2902
2913class CWindowsComLifecycle
2914{
2915public:
2916 CWindowsComLifecycle(bool HasWindow);
2917 ~CWindowsComLifecycle();
2918};
2919
2933bool shell_register_protocol(const char *protocol_name, const char *executable, bool *updated);
2934
2950bool shell_register_extension(const char *extension, const char *description, const char *executable_name, const char *executable, bool *updated);
2951
2965bool shell_register_application(const char *name, const char *executable, bool *updated);
2966
2981bool shell_unregister_class(const char *shell_class, bool *updated);
2982
2995bool shell_unregister_application(const char *executable, bool *updated);
2996
3004void shell_update();
3005#endif
3006
3007template<>
3008struct std::hash<NETADDR>
3009{
3010 size_t operator()(const NETADDR &Addr) const noexcept;
3011};
3012
3013#endif
Definition: system.h:2855
~CCmdlineFix()
Definition: system.h:2866
int m_Argc
Definition: system.h:2856
const char ** m_ppArgv
Definition: system.h:2857
CCmdlineFix(int *pArgc, const char ***pppArgv)
Definition: system.h:2860
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:2145
const char * fs_filename(const char *path)
Definition: system.cpp:2462
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:2472
int fs_is_relative_path(const char *path)
Definition: system.cpp:2417
int fs_is_file(const char *path)
Definition: system.cpp:2389
int fs_removedir(const char *path)
Definition: system.cpp:2375
int fs_parent_dir(char *path)
Definition: system.cpp:2495
void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user)
Definition: system.cpp:2197
char * fs_getcwd(char *buffer, int buffer_size)
Definition: system.cpp:2437
int fs_is_dir(const char *path)
Definition: system.cpp:2403
int fs_file_time(const char *name, time_t *created, time_t *modified)
Definition: system.cpp:2536
int fs_makedir_rec_for(const char *path)
Definition: system.cpp:2331
int fs_storage_path(const char *appname, char *path, int max)
Definition: system.cpp:2264
int fs_chdir(const char *path)
Definition: system.cpp:2427
int fs_remove(const char *filename)
Definition: system.cpp:2512
int fs_rename(const char *oldname, const char *newname)
Definition: system.cpp:2522
int fs_makedir(const char *path)
Definition: system.cpp:2352
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
int net_addr_comp_noport(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1072
void net_init()
Definition: system.cpp:2097
int net_addr_comp(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1062
struct sockaddr_un UNIXSOCKETADDR
Definition: system.h:810
void net_addr_str(const NETADDR *addr, char *string, int max_length, bool add_port)
Definition: system.cpp:1147
int net_tcp_close(NETSOCKET sock)
Definition: system.cpp:2074
int net_tcp_listen(NETSOCKET sock, int backlog)
Definition: system.cpp:1959
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr)
Definition: system.cpp:1969
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr)
Definition: system.cpp:2016
NETSOCKET net_tcp_create(NETADDR bindaddr)
Definition: system.cpp:1882
int net_tcp_send(NETSOCKET sock, const void *data, int size)
Definition: system.cpp:2050
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize)
Definition: system.cpp:2062
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size)
Definition: system.cpp:1674
int net_udp_close(NETSOCKET sock)
Definition: system.cpp:1877
int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size)
Definition: system.cpp:2111
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path)
Definition: system.cpp:2116
UNIXSOCKET net_unix_create_unnamed()
Definition: system.cpp:2106
void net_unix_close(UNIXSOCKET sock)
Definition: system.cpp:2123
void secure_random_password(char *buffer, unsigned length, unsigned pw_length)
Definition: system.cpp:4430
void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length)
Definition: system.cpp:4410
int secure_rand()
Definition: system.cpp:4470
int secure_random_init()
Definition: system.cpp:4351
int secure_random_uninit()
Definition: system.cpp:4381
void secure_random_fill(void *bytes, unsigned length)
Definition: system.cpp:4446
int secure_rand_below(int below)
Definition: system.cpp:4489
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:4505
int kill_process(PROCESS process)
Definition: system.cpp:4243
bool is_process_alive(PROCESS process)
Definition: system.cpp:4263
EShellExecuteWindowState
Definition: system.h:2627
int open_link(const char *link)
Definition: system.cpp:4276
constexpr PROCESS INVALID_PROCESS
Definition: system.h:2615
void cmdline_free(int argc, const char **argv)
Definition: system.cpp:4185
void os_locale_str(char *locale, size_t length)
Definition: system.cpp:4584
void cmdline_fix(int *argc, const char ***argv)
Definition: system.cpp:4147
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state)
Definition: system.cpp:4194
int open_file(const char *path)
Definition: system.cpp:4316
int pid()
Definition: system.cpp:4138
pid_t PROCESS
Definition: system.h:2609
const char * str_rchr(const char *haystack, char needle)
Definition: system.cpp:3237
char * str_skip_to_whitespace(char *str)
Definition: system.cpp:2926
int str_length(const char *str)
Definition: system.cpp:2794
void str_sanitize(char *str)
Definition: system.cpp:2872
const char * str_startswith(const char *str, const char *prefix)
Definition: system.cpp:3028
bool str_has_cc(const char *str)
Definition: system.cpp:2845
void str_sanitize_cc(char *str)
Definition: system.cpp:2860
const char * str_skip_whitespaces_const(const char *str)
Definition: system.cpp:2947
const char * str_skip_to_whitespace_const(const char *str)
Definition: system.cpp:2933
int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
Definition: system.cpp:2799
int str_comp_num(const char *a, const char *b, int num)
Definition: system.cpp:2978
void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2767
int str_comp_filenames(const char *a, const char *b)
Definition: system.cpp:2983
int str_comp_nocase(const char *a, const char *b)
Definition: system.cpp:2955
void str_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2784
bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end)
Definition: system.cpp:3205
int str_countchr(const char *haystack, char needle)
Definition: system.cpp:3242
int str_comp(const char *a, const char *b)
Definition: system.cpp:2973
void str_append(char *dst, const char *src, int dst_size)
Definition: system.cpp:2743
void str_clean_whitespaces(char *str)
Definition: system.cpp:2895
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2760
char * str_skip_whitespaces(char *str)
Definition: system.cpp:2940
int str_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:2964
int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len)
Definition: system.cpp:3147
int str_isspace(char c)
Definition: system.cpp:3622
const char * str_trim_words(const char *str, int words)
Definition: system.cpp:2832
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:4700
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:2658
int64_t time_timestamp()
Definition: system.cpp:2640
ETimeSeason time_season()
Definition: system.cpp:2696
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:12
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:2180
uint64_t recv_packets
Definition: system.h:2183
uint64_t recv_bytes
Definition: system.h:2184
uint64_t sent_packets
Definition: system.h:2181
uint64_t sent_bytes
Definition: system.h:2182
void str_utf8_trim_right(char *param)
Definition: system.cpp:3808
void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line=12)
Definition: system.cpp:3269
int str_utf8_comp_nocase(const char *a, const char *b)
Definition: system.cpp:3710
void swap_endian(void *data, unsigned elem_size, unsigned num)
Definition: system.cpp:2562
size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset)
Definition: system.cpp:4056
void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num)
Definition: system.cpp:4003
NETSOCKET net_udp_create(NETADDR bindaddr)
Definition: system.cpp:1576
void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler)
Definition: system.cpp:159
int str_isallnum(const char *str)
Definition: system.cpp:3639
int str_utf8_forward(const char *str, int cursor)
Definition: system.cpp:3868
const char * str_next_token(const char *str, const char *delim, char *buffer, int buffer_size)
Definition: system.cpp:4105
int str_utf8_decode(const char **ptr)
Definition: system.cpp:3923
unsigned long str_toulong_base(const char *str, int base)
Definition: system.cpp:3683
const char * str_find_nocase(const char *haystack, const char *needle)
Definition: system.cpp:3167
int net_would_block()
Definition: system.cpp:2088
void str_base64(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3361
int net_host_lookup(const char *hostname, NETADDR *addr, int types)
Definition: system.cpp:1251
int str_utf8_encode(char *ptr, int chr)
Definition: system.cpp:3878
int str_utf8_dist(const char *a, const char *b)
Definition: system.cpp:3091
int str_toint_base(const char *str, int base)
Definition: system.cpp:3678
int str_utf8_isstart(char c)
Definition: system.cpp:3833
bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
Definition: system.cpp:3530
void str_escape(char **dst, const char *src, const char *end)
Definition: system.cpp:3601
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
Definition: system.cpp:1325
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:3111
const char * str_utf8_skip_whitespaces(const char *str)
Definition: system.cpp:3788
void str_sanitize_filename(char *str)
Definition: system.cpp:2883
int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr)
Definition: system.cpp:2039
std::function< void(const char *message)> DBG_ASSERT_HANDLER
Definition: system.h:116
int net_set_non_blocking(NETSOCKET sock)
Definition: system.cpp:1949
int str_in_list(const char *list, const char *delim, const char *needle)
Definition: system.cpp:4091
int str_utf8_comp_confusable(const char *str1, const char *str2)
Definition: confusables.cpp:83
int net_socket_type(NETSOCKET sock)
Definition: system.cpp:1571
void str_timestamp(char *buffer, int buffer_size)
Definition: system.cpp:3525
void uint_to_bytes_be(unsigned char *bytes, unsigned value)
Definition: system.cpp:4130
int str_format_int(char *buffer, size_t buffer_size, int value)
Definition: system.cpp:2811
int str_base64_decode(void *dst, int dst_size, const char *data)
Definition: system.cpp:3438
int str_time_float(float secs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3596
const NETADDR NETADDR_ZEROED
Definition: system.cpp:1002
#define GNUC_ATTRIBUTE(x)
Definition: system.h:88
int net_errno()
Definition: system.cpp:2079
int str_toint(const char *str)
Definition: system.cpp:3661
void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count)
Definition: system.cpp:4021
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
Definition: system.h:1290
int str_hex_decode(void *dst, int dst_size, const char *src)
Definition: system.cpp:3344
bool str_isnum(char c)
Definition: system.cpp:3634
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3518
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3511
float str_tofloat(const char *str)
Definition: system.cpp:3693
void str_hex(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3254
void net_stats(NETSTATS *stats)
Definition: system.cpp:3617
unsigned str_quickhash(const char *str)
Definition: system.cpp:4069
int net_socket_read_wait(NETSOCKET sock, int time)
Definition: system.cpp:2588
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:1954
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:4041
int net_addr_from_str(NETADDR *addr, const char *string)
Definition: system.cpp:1374
int str_utf8_check(const char *str)
Definition: system.cpp:3990
const char * str_utf8_find_nocase(const char *haystack, const char *needle, const char **end=nullptr)
Definition: system.cpp:3750
#define str_format
Definition: system.h:1309
int str_isallnum_hex(const char *str)
Definition: system.cpp:3650
int str_utf8_isspace(int code)
Definition: system.cpp:3777
int str_time(int64_t centisecs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3549
const char * str_startswith_nocase(const char *str, const char *prefix)
Definition: system.cpp:3015
int str_utf8_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:3726
const char * str_endswith_nocase(const char *str, const char *suffix)
Definition: system.cpp:3041
unsigned bytes_be_to_uint(const unsigned char *bytes)
Definition: system.cpp:4125
int str_utf8_rewind(const char *str, int cursor)
Definition: system.cpp:3840
int str_utf8_fix_truncation(char *str)
Definition: system.cpp:3851
const char * str_endswith(const char *str, const char *suffix)
Definition: system.cpp:3061
const char * str_find(const char *haystack, const char *needle)
Definition: system.cpp:3186
char str_uppercase(char c)
Definition: system.cpp:3627
int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data)
Definition: system.cpp:1799
int64_t str_toint64_base(const char *str, int base=10)
Definition: system.cpp:3688
int str_utf8_tolower(int code)
Definition: tolower.cpp:12
@ TIME_SECS_CENTISECS
Definition: system.h:1837
@ TIME_HOURS_CENTISECS
Definition: system.h:1835
@ TIME_DAYS
Definition: system.h:1832
@ TIME_MINS
Definition: system.h:1834
@ TIME_HOURS
Definition: system.h:1833
@ TIME_MINS_CENTISECS
Definition: system.h:1836
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