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
58#ifdef __GNUC__
59#define GNUC_ATTRIBUTE(x) __attribute__(x)
60#else
61#define GNUC_ATTRIBUTE(x)
62#endif
63
82#define dbg_assert(test, fmt, ...) \
83 do \
84 { \
85 if(!(test)) \
86 { \
87 dbg_assert_imp(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
88 } \
89 } while(false)
90
96#if defined(__cplusplus)
97[[noreturn]]
98#endif
99void
100dbg_assert_imp(const char *filename, int line, const char *fmt, ...)
101 GNUC_ATTRIBUTE((format(printf, 3, 4)));
102
103#ifdef __clang_analyzer__
104#include <cassert>
105#undef dbg_assert
106#define dbg_assert(test, fmt, ...) assert(test)
107#endif
108
119
128#if defined(__cplusplus)
129[[noreturn]]
130#endif
131void
132dbg_break();
133
134typedef std::function<void(const char *message)> DBG_ASSERT_HANDLER;
136
149void dbg_msg(const char *sys, const char *fmt, ...)
150 GNUC_ATTRIBUTE((format(printf, 2, 3)));
151
170void mem_copy(void *dest, const void *source, size_t size);
171
185void mem_move(void *dest, const void *source, size_t size);
186
195template<typename T>
196inline void mem_zero(T *block, size_t size)
197{
198 static_assert((std::is_trivially_constructible<T>::value && std::is_trivially_destructible<T>::value) || std::is_fundamental<T>::value);
199 memset(block, 0, size);
200}
201
215int mem_comp(const void *a, const void *b, size_t size);
216
227bool mem_has_null(const void *block, size_t size);
228
238enum
239{
258};
259
264{
283};
284
297IOHANDLE io_open(const char *filename, int flags);
298
310unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
311
328bool io_read_all(IOHANDLE io, void **result, unsigned *result_len);
329
346char *io_read_all_str(IOHANDLE io);
347
358int io_skip(IOHANDLE io, int64_t size);
359
371int io_seek(IOHANDLE io, int64_t offset, ESeekOrigin origin);
372
382int64_t io_tell(IOHANDLE io);
383
393int64_t io_length(IOHANDLE io);
394
406unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
407
418
428int io_close(IOHANDLE io);
429
439int io_flush(IOHANDLE io);
440
450int io_sync(IOHANDLE io);
451
461int io_error(IOHANDLE io);
462
473
484
495
504
510typedef struct ASYNCIO ASYNCIO;
511
522
531void aio_lock(ASYNCIO *aio);
532
541void aio_unlock(ASYNCIO *aio);
542
552void aio_write(ASYNCIO *aio, const void *buffer, unsigned size);
553
561void aio_write_newline(ASYNCIO *aio);
562
573void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size);
574
584
599int aio_error(ASYNCIO *aio);
600
608void aio_close(ASYNCIO *aio);
609
617void aio_wait(ASYNCIO *aio);
618
626void aio_free(ASYNCIO *aio);
627
647void *thread_init(void (*threadfunc)(void *), void *user, const char *name);
648
656void thread_wait(void *thread);
657
663void thread_yield();
664
674void thread_detach(void *thread);
675
685void thread_init_and_detach(void (*threadfunc)(void *), void *user, const char *name);
686
692#if defined(CONF_FAMILY_WINDOWS)
693typedef void *SEMAPHORE;
694#elif defined(CONF_PLATFORM_MACOS)
695#include <semaphore.h>
696typedef sem_t *SEMAPHORE;
697#elif defined(CONF_FAMILY_UNIX)
698#include <semaphore.h>
699typedef sem_t SEMAPHORE;
700#else
701#error not implemented on this platform
702#endif
703
707void sphore_init(SEMAPHORE *sem);
711void sphore_wait(SEMAPHORE *sem);
715void sphore_signal(SEMAPHORE *sem);
719void sphore_destroy(SEMAPHORE *sem);
720
730void set_new_tick();
731
743int64_t time_get_impl();
744
757int64_t time_get();
758
764int64_t time_freq();
765
773int64_t time_timestamp();
774
783
788{
798
809
814extern const NETADDR NETADDR_ZEROED;
815
820#ifdef CONF_FAMILY_UNIX
824typedef int UNIXSOCKET;
828typedef struct sockaddr_un UNIXSOCKETADDR;
829#endif
830
838void net_init();
839
840/*
841 Function: net_host_lookup
842 Does a hostname lookup by name and fills out the passed
843 NETADDR struct with the received details.
844
845 Returns:
846 0 on success.
847*/
848int net_host_lookup(const char *hostname, NETADDR *addr, int types);
849
862int net_addr_comp(const NETADDR *a, const NETADDR *b);
863
876int net_addr_comp_noport(const NETADDR *a, const NETADDR *b);
877
890void net_addr_str(const NETADDR *addr, char *string, int max_length, bool add_port);
891
915int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size);
916
924bool net_addr_is_local(const NETADDR *addr);
925
934int net_addr_from_str(NETADDR *addr, const char *string);
935
941/*
942 Function: net_socket_type
943 Determine a socket's type.
944
945 Parameters:
946 sock - Socket whose type should be determined.
947
948 Returns:
949 The socket type, a bitset of `NETTYPE_IPV4`, `NETTYPE_IPV6` and
950 `NETTYPE_WEBSOCKET_IPV4`.
951*/
952int net_socket_type(NETSOCKET sock);
953
954/*
955 Function: net_udp_create
956 Creates a UDP socket and binds it to a port.
957
958 Parameters:
959 bindaddr - Address to bind the socket to.
960
961 Returns:
962 On success it returns an handle to the socket. On failure it
963 returns NETSOCKET_INVALID.
964*/
966
980int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
981
982/*
983 Function: net_udp_recv
984 Receives a packet over an UDP socket.
985
986 Parameters:
987 sock - Socket to use.
988 addr - Pointer to an NETADDR that will receive the address.
989 data - Received data. Will be invalidated when this function is
990 called again.
991
992 Returns:
993 On success it returns the number of bytes received. Returns -1
994 on error.
995*/
996int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data);
997
1007int net_udp_close(NETSOCKET sock);
1008
1024
1035int net_tcp_listen(NETSOCKET sock, int backlog);
1036
1048int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
1049
1061int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
1062
1074int net_tcp_send(NETSOCKET sock, const void *data, int size);
1075
1089int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
1090
1100int net_tcp_close(NETSOCKET sock);
1101
1102#if defined(CONF_FAMILY_UNIX)
1116
1129int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size);
1130
1139void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path);
1140
1148void net_unix_close(UNIXSOCKET sock);
1149
1150#elif defined(CONF_FAMILY_WINDOWS)
1151
1159std::string windows_format_system_message(unsigned long error);
1160
1161#endif
1162
1181void str_append(char *dst, const char *src, int dst_size);
1182
1194template<int N>
1195void str_append(char (&dst)[N], const char *src)
1196{
1197 str_append(dst, src, N);
1198}
1199
1214int str_copy(char *dst, const char *src, int dst_size);
1215
1227template<int N>
1228void str_copy(char (&dst)[N], const char *src)
1229{
1230 str_copy(dst, src, N);
1231}
1232
1246void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1247
1262void str_truncate(char *dst, int dst_size, const char *src, int truncation_len);
1263
1273int str_length(const char *str);
1274
1291int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
1292 GNUC_ATTRIBUTE((format(printf, 3, 0)));
1293
1310int str_format(char *buffer, int buffer_size, const char *format, ...)
1311 GNUC_ATTRIBUTE((format(printf, 3, 4)));
1312
1313#if !defined(CONF_DEBUG)
1314int str_format_int(char *buffer, size_t buffer_size, int value);
1315
1316template<typename... Args>
1317int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
1318{
1319 static_assert(sizeof...(args) > 0, "Use str_copy instead of str_format without format arguments");
1320 return str_format(buffer, buffer_size, format, args...);
1321}
1322
1323template<>
1324inline int str_format_opt(char *buffer, int buffer_size, const char *format, int val)
1325{
1326 if(strcmp(format, "%d") == 0)
1327 {
1328 return str_format_int(buffer, buffer_size, val);
1329 }
1330 else
1331 {
1332 return str_format(buffer, buffer_size, format, val);
1333 }
1334}
1335
1336#define str_format str_format_opt
1337#endif
1338
1352const char *str_trim_words(const char *str, int words);
1353
1365bool str_has_cc(const char *str);
1366
1376void str_sanitize_cc(char *str);
1377
1388void str_sanitize(char *str);
1389
1397void str_sanitize_filename(char *str);
1398
1408void str_clean_whitespaces(char *str);
1409
1423char *str_skip_to_whitespace(char *str);
1424
1429const char *str_skip_to_whitespace_const(const char *str);
1430
1444char *str_skip_whitespaces(char *str);
1445
1450const char *str_skip_whitespaces_const(const char *str);
1451
1467int str_comp_nocase(const char *a, const char *b);
1468
1486int str_comp_nocase_num(const char *a, const char *b, int num);
1487
1502int str_comp(const char *a, const char *b);
1503
1519int str_comp_num(const char *a, const char *b, int num);
1520
1535int str_comp_filenames(const char *a, const char *b);
1536
1537/*
1538 Function: str_startswith_nocase
1539 Checks case insensitive whether the string begins with a certain prefix.
1540
1541 Parameter:
1542 str - String to check.
1543 prefix - Prefix to look for.
1544
1545 Returns:
1546 A pointer to the string str after the string prefix, or 0 if
1547 the string prefix isn't a prefix of the string str.
1548
1549 Remarks:
1550 - The strings are treated as zero-terminated strings.
1551*/
1552const char *str_startswith_nocase(const char *str, const char *prefix);
1553
1567const char *str_startswith(const char *str, const char *prefix);
1568
1569/*
1570 Function: str_endswith_nocase
1571 Checks case insensitive whether the string ends with a certain suffix.
1572
1573 Parameter:
1574 str - String to check.
1575 suffix - Suffix to look for.
1576
1577 Returns:
1578 A pointer to the beginning of the suffix in the string str, or
1579 0 if the string suffix isn't a suffix of the string str.
1580
1581 Remarks:
1582 - The strings are treated as zero-terminated strings.
1583*/
1584const char *str_endswith_nocase(const char *str, const char *suffix);
1585
1586/*
1587 Function: str_endswith
1588 Checks case sensitive whether the string ends with a certain suffix.
1589
1590 Parameter:
1591 str - String to check.
1592 suffix - Suffix to look for.
1593
1594 Returns:
1595 A pointer to the beginning of the suffix in the string str, or
1596 0 if the string suffix isn't a suffix of the string str.
1597
1598 Remarks:
1599 - The strings are treated as zero-terminated strings.
1600*/
1601const char *str_endswith(const char *str, const char *suffix);
1602
1613int str_utf8_dist(const char *a, const char *b);
1614
1631int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len);
1632
1633/*
1634 Function: str_utf32_dist_buffer
1635 Computes the edit distance between two strings, allows buffers
1636 to be passed in.
1637
1638 Parameters:
1639 a - First string for the edit distance.
1640 a_len - Length of the first string.
1641 b - Second string for the edit distance.
1642 b_len - Length of the second string.
1643 buf - Buffer for the function.
1644 buf_len - Length of the buffer, must be at least as long as
1645 the length of both strings combined plus two.
1646
1647 Returns:
1648 The edit distance between the both strings.
1649
1650 Remarks:
1651 - The strings are treated as zero-terminated strings.
1652*/
1653int str_utf32_dist_buffer(const int *a, int a_len, const int *b, int b_len, int *buf, int buf_len);
1654
1655/*
1656 Function: str_find_nocase
1657 Finds a string inside another string case insensitively.
1658
1659 Parameters:
1660 haystack - String to search in
1661 needle - String to search for
1662
1663 Returns:
1664 A pointer into haystack where the needle was found.
1665 Returns NULL if needle could not be found.
1666
1667 Remarks:
1668 - Only guaranteed to work with a-z/A-Z.
1669 (use str_utf8_find_nocase for unicode support)
1670 - The strings are treated as zero-terminated strings.
1671*/
1672const char *str_find_nocase(const char *haystack, const char *needle);
1673
1674/*
1675 Function: str_find
1676 Finds a string inside another string case sensitive.
1677
1678 Parameters:
1679 haystack - String to search in
1680 needle - String to search for
1681
1682 Returns:
1683 A pointer into haystack where the needle was found.
1684 Returns NULL if needle could not be found.
1685
1686 Remarks:
1687 - The strings are treated as zero-terminated strings.
1688*/
1689const char *str_find(const char *haystack, const char *needle);
1690
1705bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end);
1706
1721const char *str_rchr(const char *haystack, char needle);
1722
1737int str_countchr(const char *haystack, char needle);
1738
1749void str_hex(char *dst, int dst_size, const void *data, int data_size);
1750
1765void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line = 12);
1766
1767/*
1768 Function: str_hex_decode
1769 Takes a hex string *without spaces between bytes* and returns a
1770 byte array.
1771
1772 Parameters:
1773 dst - Buffer for the byte array
1774 dst_size - size of the buffer
1775 data - String to decode
1776
1777 Returns:
1778 2 - String doesn't exactly fit the buffer
1779 1 - Invalid character in string
1780 0 - Success
1781
1782 Remarks:
1783 - The contents of the buffer is only valid on success
1784*/
1785int str_hex_decode(void *dst, int dst_size, const char *src);
1786
1787/*
1788 Function: str_base64
1789 Takes a datablock and generates the base64 encoding of it.
1790
1791 Parameters:
1792 dst - Buffer to fill with base64 data
1793 dst_size - Size of the buffer
1794 data - Data to turn into base64
1795 data - Size of the data
1796
1797 Remarks:
1798 - The destination buffer will be zero-terminated
1799*/
1800void str_base64(char *dst, int dst_size, const void *data, int data_size);
1801
1802/*
1803 Function: str_base64_decode
1804 Takes a base64 string without any whitespace and correct
1805 padding and returns a byte array.
1806
1807 Parameters:
1808 dst - Buffer for the byte array
1809 dst_size - Size of the buffer
1810 data - String to decode
1811
1812 Returns:
1813 <0 - Error
1814 >= 0 - Success, length of the resulting byte buffer
1815
1816 Remarks:
1817 - The contents of the buffer is only valid on success
1818*/
1819int str_base64_decode(void *dst, int dst_size, const char *data);
1820
1821/*
1822 Function: str_timestamp
1823 Copies a time stamp in the format year-month-day_hour-minute-second to the string.
1824
1825 Parameters:
1826 buffer - Pointer to a buffer that shall receive the time stamp string.
1827 buffer_size - Size of the buffer.
1828
1829 Remarks:
1830 - Guarantees that buffer string will contain zero-termination.
1831*/
1832void str_timestamp(char *buffer, int buffer_size);
1833void str_timestamp_format(char *buffer, int buffer_size, const char *format)
1834 GNUC_ATTRIBUTE((format(strftime, 3, 0)));
1835void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
1836 GNUC_ATTRIBUTE((format(strftime, 4, 0)));
1837
1850bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
1851 GNUC_ATTRIBUTE((format(strftime, 2, 0)));
1852
1853#define FORMAT_TIME "%H:%M:%S"
1854#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
1855#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
1856
1857enum
1858{
1865};
1866
1867/*
1868 Function: str_times
1869 Formats a time string.
1870
1871 Parameters:
1872 centisecs - Time in centiseconds, minimum value clamped to 0
1873 format - Format of the time string, see enum above, for example TIME_DAYS
1874 buffer - Pointer to a buffer that shall receive the time stamp string.
1875 buffer_size - Size of the buffer.
1876
1877 Returns:
1878 Number of bytes written, -1 on invalid format or buffer_size <= 0
1879
1880 Remarks:
1881 - Guarantees that buffer string will contain zero-termination, assuming
1882 buffer_size > 0.
1883*/
1884int str_time(int64_t centisecs, int format, char *buffer, int buffer_size);
1885int str_time_float(float secs, int format, char *buffer, int buffer_size);
1886
1887/*
1888 Function: str_escape
1889 Escapes \ and " characters in a string.
1890
1891 Parameters:
1892 dst - Destination array pointer, gets increased, will point to
1893 the terminating null.
1894 src - Source array
1895 end - End of destination array
1896*/
1897void str_escape(char **dst, const char *src, const char *end);
1898
1917void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
1918
1931void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user);
1932
1947int fs_makedir(const char *path);
1948
1962int fs_removedir(const char *path);
1963
1975int fs_makedir_rec_for(const char *path);
1976
1994int fs_storage_path(const char *appname, char *path, int max);
1995
2008int fs_is_file(const char *path);
2009
2022int fs_is_dir(const char *path);
2023
2035int fs_is_relative_path(const char *path);
2036
2048int fs_chdir(const char *path);
2049
2062char *fs_getcwd(char *buffer, int buffer_size);
2063
2078const char *fs_filename(const char *path);
2079
2095void fs_split_file_extension(const char *filename, char *name, size_t name_size, char *extension = nullptr, size_t extension_size = 0);
2096
2108int fs_parent_dir(char *path);
2109
2122int fs_remove(const char *filename);
2123
2136int fs_rename(const char *oldname, const char *newname);
2137
2152int fs_file_time(const char *name, time_t *created, time_t *modified);
2153
2154/*
2155 Group: Undocumented
2156*/
2157
2158/*
2159 Function: net_tcp_connect_non_blocking
2160
2161 DOCTODO: serp
2162*/
2164
2165/*
2166 Function: net_set_non_blocking
2167
2168 DOCTODO: serp
2169*/
2171
2172/*
2173 Function: net_set_non_blocking
2174
2175 DOCTODO: serp
2176*/
2177int net_set_blocking(NETSOCKET sock);
2178
2179/*
2180 Function: net_errno
2181
2182 DOCTODO: serp
2183*/
2184int net_errno();
2185
2186/*
2187 Function: net_would_block
2188
2189 DOCTODO: serp
2190*/
2191int net_would_block();
2192
2193int net_socket_read_wait(NETSOCKET sock, int time);
2194
2204void swap_endian(void *data, unsigned elem_size, unsigned num);
2205
2206typedef struct
2207{
2209 uint64_t sent_bytes;
2211 uint64_t recv_bytes;
2212} NETSTATS;
2213
2214void net_stats(NETSTATS *stats);
2215
2216int str_toint(const char *str);
2217bool str_toint(const char *str, int *out);
2218int str_toint_base(const char *str, int base);
2219unsigned long str_toulong_base(const char *str, int base);
2220int64_t str_toint64_base(const char *str, int base = 10);
2221float str_tofloat(const char *str);
2222bool str_tofloat(const char *str, float *out);
2223
2235int str_isspace(char c);
2236
2237char str_uppercase(char c);
2238
2239bool str_isnum(char c);
2240
2241int str_isallnum(const char *str);
2242
2243int str_isallnum_hex(const char *str);
2244
2245unsigned str_quickhash(const char *str);
2246
2247int str_utf8_to_skeleton(const char *str, int *buf, int buf_len);
2248
2249/*
2250 Function: str_utf8_comp_confusable
2251 Compares two strings for visual appearance.
2252
2253 Parameters:
2254 str1 - String to compare.
2255 str2 - String to compare.
2256
2257 Returns:
2258 0 if the strings are confusable.
2259 !=0 otherwise.
2260*/
2261int str_utf8_comp_confusable(const char *str1, const char *str2);
2262
2263/*
2264 Function: str_utf8_tolower
2265 Converts the given Unicode codepoint to lowercase (locale insensitive).
2266
2267 Parameters:
2268 code - Unicode codepoint to convert.
2269
2270 Returns:
2271 Lowercase codepoint
2272*/
2273int str_utf8_tolower(int code);
2274
2275/*
2276 Function: str_utf8_comp_nocase
2277 Compares two utf8 strings case insensitively.
2278
2279 Parameters:
2280 a - String to compare.
2281 b - String to compare.
2282
2283 Returns:
2284 <0 - String a is less than string b
2285 0 - String a is equal to string b
2286 >0 - String a is greater than string b
2287*/
2288int str_utf8_comp_nocase(const char *a, const char *b);
2289
2290/*
2291 Function: str_utf8_comp_nocase_num
2292 Compares up to num bytes of two utf8 strings case insensitively.
2293
2294 Parameters:
2295 a - String to compare.
2296 b - String to compare.
2297 num - Maximum bytes to compare
2298
2299 Returns:
2300 <0 - String a is less than string b
2301 0 - String a is equal to string b
2302 >0 - String a is greater than string b
2303*/
2304int str_utf8_comp_nocase_num(const char *a, const char *b, int num);
2305
2306/*
2307 Function: str_utf8_find_nocase
2308 Finds a utf8 string inside another utf8 string case insensitively.
2309
2310 Parameters:
2311 haystack - String to search in
2312 needle - String to search for
2313 end - A pointer that will be set to a pointer into haystack directly behind the
2314 last character where the needle was found. Will be set to nullptr if needle
2315 could not be found. Optional parameter.
2316
2317 Returns:
2318 A pointer into haystack where the needle was found.
2319 Returns NULL if needle could not be found.
2320
2321 Remarks:
2322 - The strings are treated as zero-terminated strings.
2323*/
2324const char *str_utf8_find_nocase(const char *haystack, const char *needle, const char **end = nullptr);
2325
2326/*
2327 Function: str_utf8_isspace
2328 Checks whether the given Unicode codepoint renders as space.
2329
2330 Parameters:
2331 code - Unicode codepoint to check.
2332
2333 Returns:
2334 0 if the codepoint does not render as space, != 0 if it does.
2335*/
2336int str_utf8_isspace(int code);
2337
2338int str_utf8_isstart(char c);
2339
2340/*
2341 Function: str_utf8_skip_whitespaces
2342 Skips leading characters that render as spaces.
2343
2344 Parameters:
2345 str - Pointer to the string.
2346
2347 Returns:
2348 Pointer to the first non-whitespace character found
2349 within the string.
2350
2351 Remarks:
2352 - The strings are treated as zero-terminated strings.
2353*/
2354const char *str_utf8_skip_whitespaces(const char *str);
2355
2356/*
2357 Function: str_utf8_trim_right
2358 Removes trailing characters that render as spaces by modifying
2359 the string in-place.
2360
2361 Parameters:
2362 param - Pointer to the string.
2363
2364 Remarks:
2365 - The strings are treated as zero-terminated strings.
2366 - The string is modified in-place.
2367*/
2368void str_utf8_trim_right(char *param);
2369
2370/*
2371 Function: str_utf8_rewind
2372 Moves a cursor backwards in an utf8 string
2373
2374 Parameters:
2375 str - utf8 string
2376 cursor - position in the string
2377
2378 Returns:
2379 New cursor position.
2380
2381 Remarks:
2382 - Won't move the cursor less then 0
2383*/
2384int str_utf8_rewind(const char *str, int cursor);
2385
2386/*
2387 Function: str_utf8_fix_truncation
2388 Fixes truncation of a Unicode character at the end of a UTF-8
2389 string.
2390
2391 Returns:
2392 The new string length.
2393
2394 Parameters:
2395 str - utf8 string
2396*/
2397int str_utf8_fix_truncation(char *str);
2398
2399/*
2400 Function: str_utf8_forward
2401 Moves a cursor forwards in an utf8 string
2402
2403 Parameters:
2404 str - utf8 string
2405 cursor - position in the string
2406
2407 Returns:
2408 New cursor position.
2409
2410 Remarks:
2411 - Won't move the cursor beyond the zero termination marker
2412*/
2413int str_utf8_forward(const char *str, int cursor);
2414
2415/*
2416 Function: str_utf8_decode
2417 Decodes a utf8 codepoint
2418
2419 Parameters:
2420 ptr - Pointer to a utf8 string. This pointer will be moved forward.
2421
2422 Returns:
2423 The Unicode codepoint. -1 for invalid input and 0 for end of string.
2424
2425 Remarks:
2426 - This function will also move the pointer forward.
2427 - You may call this function again after an error occurred.
2428*/
2429int str_utf8_decode(const char **ptr);
2430
2431/*
2432 Function: str_utf8_encode
2433 Encode an utf8 character
2434
2435 Parameters:
2436 ptr - Pointer to a buffer that should receive the data. Should be able to hold at least 4 bytes.
2437
2438 Returns:
2439 Number of bytes put into the buffer.
2440
2441 Remarks:
2442 - Does not do zero termination of the string.
2443*/
2444int str_utf8_encode(char *ptr, int chr);
2445
2446/*
2447 Function: str_utf8_check
2448 Checks if a strings contains just valid utf8 characters.
2449
2450 Parameters:
2451 str - Pointer to a possible utf8 string.
2452
2453 Returns:
2454 0 - invalid characters found.
2455 1 - only valid characters found.
2456
2457 Remarks:
2458 - The string is treated as zero-terminated utf8 string.
2459*/
2460int str_utf8_check(const char *str);
2461
2462/*
2463 Function: str_utf8_copy_num
2464 Copies a number of utf8 characters from one string to another.
2465
2466 Parameters:
2467 dst - Pointer to a buffer that shall receive the string.
2468 src - String to be copied.
2469 dst_size - Size of the buffer dst.
2470 num - maximum number of utf8 characters to be copied.
2471
2472 Remarks:
2473 - The strings are treated as zero-terminated strings.
2474 - Garantees that dst string will contain zero-termination.
2475*/
2476void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num);
2477
2478/*
2479 Function: str_utf8_stats
2480 Determines the byte size and utf8 character count of a utf8 string.
2481
2482 Parameters:
2483 str - Pointer to the string.
2484 max_size - Maximum number of bytes to count.
2485 max_count - Maximum number of utf8 characters to count.
2486 size - Pointer to store size (number of non-zero bytes) of the string.
2487 count - Pointer to store count of utf8 characters of the string.
2488
2489 Remarks:
2490 - The string is treated as zero-terminated utf8 string.
2491 - It's the user's responsibility to make sure the bounds are aligned.
2492*/
2493void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count);
2494
2506size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset);
2507
2519size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset);
2520
2521/*
2522 Function: str_next_token
2523 Writes the next token after str into buf, returns the rest of the string.
2524
2525 Parameters:
2526 str - Pointer to string.
2527 delim - Delimiter for tokenization.
2528 buffer - Buffer to store token in.
2529 buffer_size - Size of the buffer.
2530
2531 Returns:
2532 Pointer to rest of the string.
2533
2534 Remarks:
2535 - The token is always null-terminated.
2536*/
2537const char *str_next_token(const char *str, const char *delim, char *buffer, int buffer_size);
2538
2539/*
2540 Function: str_in_list
2541 Checks if needle is in list delimited by delim
2542
2543 Parameters:
2544 list - List
2545 delim - List delimiter.
2546 needle - Item that is being looked for.
2547
2548 Returns:
2549 1 - Item is in list.
2550 0 - Item isn't in list.
2551*/
2552int str_in_list(const char *list, const char *delim, const char *needle);
2553
2566unsigned bytes_be_to_uint(const unsigned char *bytes);
2567
2579void uint_to_bytes_be(unsigned char *bytes, unsigned value);
2580
2593int pid();
2594
2605void cmdline_fix(int *argc, const char ***argv);
2606
2615void cmdline_free(int argc, const char **argv);
2616
2617#if defined(CONF_FAMILY_WINDOWS)
2623typedef void *PROCESS;
2629constexpr PROCESS INVALID_PROCESS = nullptr;
2630#else
2636typedef pid_t PROCESS;
2643#endif
2644#if !defined(CONF_PLATFORM_ANDROID)
2654{
2658 FOREGROUND,
2659
2663 BACKGROUND,
2664};
2665
2666#if defined(CONF_FAMILY_WINDOWS)
2677std::wstring windows_args_to_wide(const char **arguments, const size_t num_arguments);
2678#endif
2679
2692PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state, const char **arguments = nullptr, const size_t num_arguments = 0);
2693
2703int kill_process(PROCESS process);
2704
2715bool is_process_alive(PROCESS process);
2716
2729int open_link(const char *link);
2730
2743int open_file(const char *path);
2744#endif // !defined(CONF_PLATFORM_ANDROID)
2745
2761void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length);
2762
2771[[nodiscard]] int secure_random_init();
2772
2781
2794void secure_random_password(char *buffer, unsigned length, unsigned pw_length);
2795
2804void secure_random_fill(void *bytes, unsigned length);
2805
2815int secure_rand();
2816
2827int secure_rand_below(int below);
2828
2839bool os_version_str(char *version, size_t length);
2840
2855void os_locale_str(char *locale, size_t length);
2856
2857#if defined(CONF_EXCEPTION_HANDLING)
2868void init_exception_handler();
2869
2877void set_exception_handler_log_file(const char *log_file_path);
2878#endif
2879
2887std::chrono::nanoseconds time_get_nanoseconds();
2888
2889int net_socket_read_wait(NETSOCKET sock, std::chrono::nanoseconds nanoseconds);
2890
2898{
2900 const char **m_ppArgv;
2901
2902public:
2903 CCmdlineFix(int *pArgc, const char ***pppArgv)
2904 {
2905 cmdline_fix(pArgc, pppArgv);
2906 m_Argc = *pArgc;
2907 m_ppArgv = *pppArgv;
2908 }
2910 {
2912 }
2913};
2914
2915#if defined(CONF_FAMILY_WINDOWS)
2929std::wstring windows_utf8_to_wide(const char *str);
2930
2944std::optional<std::string> windows_wide_to_utf8(const wchar_t *wide_str);
2945
2956class CWindowsComLifecycle
2957{
2958public:
2959 CWindowsComLifecycle(bool HasWindow);
2960 ~CWindowsComLifecycle();
2961};
2962
2976bool shell_register_protocol(const char *protocol_name, const char *executable, bool *updated);
2977
2993bool shell_register_extension(const char *extension, const char *description, const char *executable_name, const char *executable, bool *updated);
2994
3008bool shell_register_application(const char *name, const char *executable, bool *updated);
3009
3024bool shell_unregister_class(const char *shell_class, bool *updated);
3025
3038bool shell_unregister_application(const char *executable, bool *updated);
3039
3047void shell_update();
3048#endif
3049
3050template<>
3051struct std::hash<NETADDR>
3052{
3053 size_t operator()(const NETADDR &Addr) const noexcept;
3054};
3055
3056#endif
Definition: system.h:2898
~CCmdlineFix()
Definition: system.h:2909
int m_Argc
Definition: system.h:2899
const char ** m_ppArgv
Definition: system.h:2900
CCmdlineFix(int *pArgc, const char ***pppArgv)
Definition: system.h:2903
void dbg_assert_imp(const char *filename, int line, const char *fmt,...)
Definition: system.cpp:130
void dbg_break()
Definition: system.cpp:152
bool dbg_assert_has_failed()
Definition: system.cpp:125
void dbg_msg(const char *sys, const char *fmt,...)
Definition: system.cpp:166
void aio_write_newline_unlocked(ASYNCIO *aio)
Definition: system.cpp:743
IOHANDLE io_current_exe()
Definition: system.cpp:454
void aio_wait(ASYNCIO *aio)
Definition: system.cpp:774
void aio_write_unlocked(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:686
int io_flush(IOHANDLE io)
Definition: system.cpp:416
ESeekOrigin
Definition: system.h:264
int64_t io_tell(IOHANDLE io)
Definition: system.cpp:374
IOHANDLE io_stderr()
Definition: system.cpp:449
IOHANDLE io_open(const char *filename, int flags)
Definition: system.cpp:204
int io_close(IOHANDLE io)
Definition: system.cpp:411
char * io_read_all_str(IOHANDLE io)
Definition: system.cpp:328
void aio_write(ASYNCIO *aio, const void *buffer, unsigned size)
Definition: system.cpp:736
void aio_write_newline(ASYNCIO *aio)
Definition: system.cpp:752
int io_skip(IOHANDLE io, int64_t size)
Definition: system.cpp:344
int aio_error(ASYNCIO *aio)
Definition: system.cpp:759
void aio_free(ASYNCIO *aio)
Definition: system.cpp:790
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size)
Definition: system.cpp:397
bool io_write_newline(IOHANDLE io)
Definition: system.cpp:402
bool io_read_all(IOHANDLE io, void **result, unsigned *result_len)
Definition: system.cpp:271
void aio_lock(ASYNCIO *aio)
Definition: system.cpp:675
void aio_close(ASYNCIO *aio)
Definition: system.cpp:765
int io_sync(IOHANDLE io)
Definition: system.cpp:421
int io_seek(IOHANDLE io, int64_t offset, ESeekOrigin origin)
Definition: system.cpp:349
IOHANDLE io_stdin()
Definition: system.cpp:439
int io_error(IOHANDLE io)
Definition: system.cpp:434
IOHANDLE io_stdout()
Definition: system.cpp:444
ASYNCIO * aio_new(IOHANDLE io)
Definition: system.cpp:618
void aio_unlock(ASYNCIO *aio)
Definition: system.cpp:680
int64_t io_length(IOHANDLE io)
Definition: system.cpp:383
unsigned io_read(IOHANDLE io, void *buffer, unsigned size)
Definition: system.cpp:266
@ IOSEEK_END
Definition: system.h:282
@ IOSEEK_CUR
Definition: system.h:276
@ IOSEEK_START
Definition: system.h:270
@ IOFLAG_APPEND
Definition: system.h:257
@ IOFLAG_WRITE
Definition: system.h:251
@ IOFLAG_READ
Definition: system.h:245
void fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user)
Definition: system.cpp:2156
const char * fs_filename(const char *path)
Definition: system.cpp:2473
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:2483
int fs_is_relative_path(const char *path)
Definition: system.cpp:2428
int fs_is_file(const char *path)
Definition: system.cpp:2400
int fs_removedir(const char *path)
Definition: system.cpp:2386
int fs_parent_dir(char *path)
Definition: system.cpp:2506
void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int type, void *user)
Definition: system.cpp:2208
char * fs_getcwd(char *buffer, int buffer_size)
Definition: system.cpp:2448
int fs_is_dir(const char *path)
Definition: system.cpp:2414
int fs_file_time(const char *name, time_t *created, time_t *modified)
Definition: system.cpp:2547
int fs_makedir_rec_for(const char *path)
Definition: system.cpp:2342
int fs_storage_path(const char *appname, char *path, int max)
Definition: system.cpp:2275
int fs_chdir(const char *path)
Definition: system.cpp:2438
int fs_remove(const char *filename)
Definition: system.cpp:2523
int fs_rename(const char *oldname, const char *newname)
Definition: system.cpp:2533
int fs_makedir(const char *path)
Definition: system.cpp:2363
void mem_zero(T *block, size_t size)
Definition: system.h:196
void mem_copy(void *dest, const void *source, size_t size)
Definition: system.cpp:176
bool mem_has_null(const void *block, size_t size)
Definition: system.cpp:191
void mem_move(void *dest, const void *source, size_t size)
Definition: system.cpp:181
int mem_comp(const void *a, const void *b, size_t size)
Definition: system.cpp:186
int UNIXSOCKET
Definition: system.h:824
int net_addr_comp_noport(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1069
void net_init()
Definition: system.cpp:2108
int net_addr_comp(const NETADDR *a, const NETADDR *b)
Definition: system.cpp:1059
struct sockaddr_un UNIXSOCKETADDR
Definition: system.h:828
void net_addr_str(const NETADDR *addr, char *string, int max_length, bool add_port)
Definition: system.cpp:1144
int net_tcp_close(NETSOCKET sock)
Definition: system.cpp:2085
int net_tcp_listen(NETSOCKET sock, int backlog)
Definition: system.cpp:1970
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr)
Definition: system.cpp:1980
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr)
Definition: system.cpp:2027
NETSOCKET net_tcp_create(NETADDR bindaddr)
Definition: system.cpp:1893
int net_tcp_send(NETSOCKET sock, const void *data, int size)
Definition: system.cpp:2061
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize)
Definition: system.cpp:2073
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size)
Definition: system.cpp:1685
int net_udp_close(NETSOCKET sock)
Definition: system.cpp:1888
int net_unix_send(UNIXSOCKET sock, UNIXSOCKETADDR *addr, void *data, int size)
Definition: system.cpp:2122
void net_unix_set_addr(UNIXSOCKETADDR *addr, const char *path)
Definition: system.cpp:2127
UNIXSOCKET net_unix_create_unnamed()
Definition: system.cpp:2117
void net_unix_close(UNIXSOCKET sock)
Definition: system.cpp:2134
void secure_random_password(char *buffer, unsigned length, unsigned pw_length)
Definition: system.cpp:4502
void generate_password(char *buffer, unsigned length, const unsigned short *random, unsigned random_length)
Definition: system.cpp:4482
int secure_rand()
Definition: system.cpp:4542
int secure_random_init()
Definition: system.cpp:4423
int secure_random_uninit()
Definition: system.cpp:4453
void secure_random_fill(void *bytes, unsigned length)
Definition: system.cpp:4518
int secure_rand_below(int below)
Definition: system.cpp:4561
void sphore_signal(SEMAPHORE *sem)
Definition: system.cpp:952
void sphore_destroy(SEMAPHORE *sem)
Definition: system.cpp:956
void sphore_init(SEMAPHORE *sem)
Definition: system.cpp:939
void sphore_wait(SEMAPHORE *sem)
Definition: system.cpp:943
bool os_version_str(char *version, size_t length)
Definition: system.cpp:4577
int kill_process(PROCESS process)
Definition: system.cpp:4315
bool is_process_alive(PROCESS process)
Definition: system.cpp:4335
EShellExecuteWindowState
Definition: system.h:2654
int open_link(const char *link)
Definition: system.cpp:4348
PROCESS shell_execute(const char *file, EShellExecuteWindowState window_state, const char **arguments=nullptr, const size_t num_arguments=0)
Definition: system.cpp:4254
constexpr PROCESS INVALID_PROCESS
Definition: system.h:2642
void cmdline_free(int argc, const char **argv)
Definition: system.cpp:4196
void os_locale_str(char *locale, size_t length)
Definition: system.cpp:4656
void cmdline_fix(int *argc, const char ***argv)
Definition: system.cpp:4158
int open_file(const char *path)
Definition: system.cpp:4388
int pid()
Definition: system.cpp:4149
pid_t PROCESS
Definition: system.h:2636
const char * str_rchr(const char *haystack, char needle)
Definition: system.cpp:3248
char * str_skip_to_whitespace(char *str)
Definition: system.cpp:2937
int str_length(const char *str)
Definition: system.cpp:2805
void str_sanitize(char *str)
Definition: system.cpp:2883
const char * str_startswith(const char *str, const char *prefix)
Definition: system.cpp:3039
bool str_has_cc(const char *str)
Definition: system.cpp:2856
void str_sanitize_cc(char *str)
Definition: system.cpp:2871
const char * str_skip_whitespaces_const(const char *str)
Definition: system.cpp:2958
const char * str_skip_to_whitespace_const(const char *str)
Definition: system.cpp:2944
int str_format_v(char *buffer, int buffer_size, const char *format, va_list args)
Definition: system.cpp:2810
int str_comp_num(const char *a, const char *b, int num)
Definition: system.cpp:2989
void str_utf8_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2778
int str_comp_filenames(const char *a, const char *b)
Definition: system.cpp:2994
int str_comp_nocase(const char *a, const char *b)
Definition: system.cpp:2966
void str_truncate(char *dst, int dst_size, const char *src, int truncation_len)
Definition: system.cpp:2795
bool str_delimiters_around_offset(const char *haystay, const char *delim, int offset, int *start, int *end)
Definition: system.cpp:3216
int str_countchr(const char *haystack, char needle)
Definition: system.cpp:3253
int str_comp(const char *a, const char *b)
Definition: system.cpp:2984
void str_append(char *dst, const char *src, int dst_size)
Definition: system.cpp:2754
void str_clean_whitespaces(char *str)
Definition: system.cpp:2906
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2771
char * str_skip_whitespaces(char *str)
Definition: system.cpp:2951
int str_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:2975
int str_utf8_dist_buffer(const char *a, const char *b, int *buf, int buf_len)
Definition: system.cpp:3158
int str_isspace(char c)
Definition: system.cpp:3633
const char * str_trim_words(const char *str, int words)
Definition: system.cpp:2843
void thread_wait(void *thread)
Definition: system.cpp:852
void * thread_init(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:826
void thread_yield()
Definition: system.cpp:864
void thread_init_and_detach(void(*threadfunc)(void *), void *user, const char *name)
Definition: system.cpp:886
void thread_detach(void *thread)
Definition: system.cpp:875
std::chrono::nanoseconds time_get_nanoseconds()
Definition: system.cpp:4772
ETimeSeason
Definition: system.h:788
void set_new_tick()
Definition: system.cpp:964
int64_t time_freq()
Definition: system.cpp:991
int time_houroftheday()
Definition: system.cpp:2669
int64_t time_timestamp()
Definition: system.cpp:2651
ETimeSeason time_season()
Definition: system.cpp:2707
int64_t time_get()
Definition: system.cpp:979
int64_t time_get_impl()
Definition: system.cpp:974
@ SEASON_AUTUMN
Definition: system.h:791
@ SEASON_WINTER
Definition: system.h:792
@ SEASON_SPRING
Definition: system.h:789
@ SEASON_HALLOWEEN
Definition: system.h:794
@ SEASON_XMAS
Definition: system.h:795
@ SEASON_EASTER
Definition: system.h:793
@ SEASON_SUMMER
Definition: system.h:790
@ SEASON_NEWYEAR
Definition: system.h:796
void * IOHANDLE
Definition: logger.h:12
Definition: system.cpp:495
void * thread
Definition: system.cpp:499
unsigned char * buffer
Definition: system.cpp:501
IOHANDLE io
Definition: system.cpp:497
Definition: types.h:67
Definition: system.cpp:110
Definition: system.h:2207
uint64_t recv_packets
Definition: system.h:2210
uint64_t recv_bytes
Definition: system.h:2211
uint64_t sent_packets
Definition: system.h:2208
uint64_t sent_bytes
Definition: system.h:2209
void str_utf8_trim_right(char *param)
Definition: system.cpp:3819
void str_hex_cstyle(char *dst, int dst_size, const void *data, int data_size, int bytes_per_line=12)
Definition: system.cpp:3280
int str_utf8_comp_nocase(const char *a, const char *b)
Definition: system.cpp:3721
void swap_endian(void *data, unsigned elem_size, unsigned num)
Definition: system.cpp:2573
size_t str_utf8_offset_chars_to_bytes(const char *str, size_t char_offset)
Definition: system.cpp:4067
void str_utf8_copy_num(char *dst, const char *src, int dst_size, int num)
Definition: system.cpp:4014
NETSOCKET net_udp_create(NETADDR bindaddr)
Definition: system.cpp:1587
void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler)
Definition: system.cpp:161
int str_isallnum(const char *str)
Definition: system.cpp:3650
int str_utf8_forward(const char *str, int cursor)
Definition: system.cpp:3879
const char * str_next_token(const char *str, const char *delim, char *buffer, int buffer_size)
Definition: system.cpp:4116
int str_utf8_decode(const char **ptr)
Definition: system.cpp:3934
unsigned long str_toulong_base(const char *str, int base)
Definition: system.cpp:3694
const char * str_find_nocase(const char *haystack, const char *needle)
Definition: system.cpp:3178
int net_would_block()
Definition: system.cpp:2099
void str_base64(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3372
int net_host_lookup(const char *hostname, NETADDR *addr, int types)
Definition: system.cpp:1248
int str_utf8_encode(char *ptr, int chr)
Definition: system.cpp:3889
int str_utf8_dist(const char *a, const char *b)
Definition: system.cpp:3102
int str_toint_base(const char *str, int base)
Definition: system.cpp:3689
int str_utf8_isstart(char c)
Definition: system.cpp:3844
bool timestamp_from_str(const char *string, const char *format, time_t *timestamp)
Definition: system.cpp:3541
void str_escape(char **dst, const char *src, const char *end)
Definition: system.cpp:3612
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
Definition: system.cpp:1322
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:3122
const char * str_utf8_skip_whitespaces(const char *str)
Definition: system.cpp:3799
void str_sanitize_filename(char *str)
Definition: system.cpp:2894
int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr)
Definition: system.cpp:2050
std::function< void(const char *message)> DBG_ASSERT_HANDLER
Definition: system.h:134
int net_set_non_blocking(NETSOCKET sock)
Definition: system.cpp:1960
int str_in_list(const char *list, const char *delim, const char *needle)
Definition: system.cpp:4102
int str_utf8_comp_confusable(const char *str1, const char *str2)
Definition: confusables.cpp:83
int net_socket_type(NETSOCKET sock)
Definition: system.cpp:1582
void str_timestamp(char *buffer, int buffer_size)
Definition: system.cpp:3536
void uint_to_bytes_be(unsigned char *bytes, unsigned value)
Definition: system.cpp:4141
int str_format_int(char *buffer, size_t buffer_size, int value)
Definition: system.cpp:2822
int str_base64_decode(void *dst, int dst_size, const char *data)
Definition: system.cpp:3449
@ TIME_SECS_CENTISECS
Definition: system.h:1864
@ TIME_HOURS_CENTISECS
Definition: system.h:1862
@ TIME_DAYS
Definition: system.h:1859
@ TIME_MINS
Definition: system.h:1861
@ TIME_HOURS
Definition: system.h:1860
@ TIME_MINS_CENTISECS
Definition: system.h:1863
int str_time_float(float secs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3607
const NETADDR NETADDR_ZEROED
Definition: system.cpp:999
#define GNUC_ATTRIBUTE(x)
Definition: system.h:61
int net_errno()
Definition: system.cpp:2090
int str_toint(const char *str)
Definition: system.cpp:3672
void str_utf8_stats(const char *str, size_t max_size, size_t max_count, size_t *size, size_t *count)
Definition: system.cpp:4032
int str_format_opt(char *buffer, int buffer_size, const char *format, Args... args)
Definition: system.h:1317
int str_hex_decode(void *dst, int dst_size, const char *src)
Definition: system.cpp:3355
bool str_isnum(char c)
Definition: system.cpp:3645
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3529
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
Definition: system.cpp:3522
float str_tofloat(const char *str)
Definition: system.cpp:3704
void str_hex(char *dst, int dst_size, const void *data, int data_size)
Definition: system.cpp:3265
void net_stats(NETSTATS *stats)
Definition: system.cpp:3628
unsigned str_quickhash(const char *str)
Definition: system.cpp:4080
int net_socket_read_wait(NETSOCKET sock, int time)
Definition: system.cpp:2599
int net_set_blocking(NETSOCKET sock)
Definition: system.cpp:1965
sem_t SEMAPHORE
Definition: system.h:699
size_t str_utf8_offset_bytes_to_chars(const char *str, size_t byte_offset)
Definition: system.cpp:4052
int net_addr_from_str(NETADDR *addr, const char *string)
Definition: system.cpp:1385
int str_utf8_check(const char *str)
Definition: system.cpp:4001
const char * str_utf8_find_nocase(const char *haystack, const char *needle, const char **end=nullptr)
Definition: system.cpp:3761
#define str_format
Definition: system.h:1336
int str_isallnum_hex(const char *str)
Definition: system.cpp:3661
int str_utf8_isspace(int code)
Definition: system.cpp:3788
int str_time(int64_t centisecs, int format, char *buffer, int buffer_size)
Definition: system.cpp:3560
const char * str_startswith_nocase(const char *str, const char *prefix)
Definition: system.cpp:3026
int str_utf8_comp_nocase_num(const char *a, const char *b, int num)
Definition: system.cpp:3737
const char * str_endswith_nocase(const char *str, const char *suffix)
Definition: system.cpp:3052
unsigned bytes_be_to_uint(const unsigned char *bytes)
Definition: system.cpp:4136
int str_utf8_rewind(const char *str, int cursor)
Definition: system.cpp:3851
int str_utf8_fix_truncation(char *str)
Definition: system.cpp:3862
const char * str_endswith(const char *str, const char *suffix)
Definition: system.cpp:3072
const char * str_find(const char *haystack, const char *needle)
Definition: system.cpp:3197
bool net_addr_is_local(const NETADDR *addr)
Definition: system.cpp:1371
char str_uppercase(char c)
Definition: system.cpp:3638
int net_udp_recv(NETSOCKET sock, NETADDR *addr, unsigned char **data)
Definition: system.cpp:1810
int64_t str_toint64_base(const char *str, int base=10)
Definition: system.cpp:3699
int str_utf8_tolower(int code)
Definition: tolower.cpp:12
int str_utf8_to_skeleton(const char *str, int *buf, int buf_len)
Definition: confusables.cpp:66
int(* FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user)
Definition: types.h:29
int(* FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user)
Definition: types.h:20
float length(const vector2_base< float > &a)
Definition: vmath.h:104