14 #include <drift/dslcore.h>
15 #include <drift/GenLib.h>
16 #include <drift/Mutex.h>
17 #include <drift/rwops.h>
21 time_t filetime_2_time_t(FILETIME ft) {
23 tmp.LowPart = ft.dwLowDateTime;
24 tmp.HighPart = ft.dwHighDateTime;
25 uint64 ret = (tmp.QuadPart - 0x19DB1DED53E8000) / 10000000;
33 string = dsl_strdup(str);
40 bool ends_in_sep =
false;
41 if (
string[strlen(
string) - 1] == sep) {
48 char * p = strtok_r(
string, sep_str, &p2);
51 tokens = (
char **)dsl_realloc(tokens,
sizeof(
char *) * num_tokens);
52 tokens[num_tokens - 1] = p;
53 p = strtok_r(NULL, sep_str, &p2);
57 tokens = (
char **)dsl_realloc(tokens,
sizeof(
char *) * num_tokens);
58 tokens[num_tokens - 1] = p2;
64 StrTokenizer::~StrTokenizer() {
71 size_t StrTokenizer::NumTok() {
75 char * StrTokenizer::GetTok(
size_t first,
size_t last) {
78 char * ret = (
char *)dsl_malloc(lSize);
81 first = clamp<size_t>(first, 1, num_tokens);
82 last = clamp<size_t>(last, 1, num_tokens);
83 for (
size_t i = (first - 1); i < last; i++) {
85 lSize += strlen(tokens[i]) + 1;
86 ret = (
char *)dsl_realloc(ret, lSize);
90 lSize += strlen(tokens[i]);
91 ret = (
char *)dsl_realloc(ret, lSize);
99 char * StrTokenizer::GetSingleTok(
size_t num) {
100 return GetTok(num, num);
107 std::string StrTokenizer::stdGetTok(
size_t first,
size_t last) {
111 first = clamp<size_t>(first, 1, num_tokens);
112 last = clamp<size_t>(last, 1, num_tokens);
113 for (
size_t i = (first - 1); i < last; i++) {
125 std::string StrTokenizer::stdGetSingleTok(
size_t num) {
126 return stdGetTok(num, num);
129 char * DSL_CC
bin2hex(
const uint8_t * data,
size_t datalen,
char * out,
size_t outsize) {
133 if (outsize < (datalen * 2) + 1) {
143 for (i = 0; i < datalen; i++) {
144 j = (data[i] >> 4) & 0xf;
146 out[i * 2] = (j +
'0');
148 out[i * 2] = (j +
'a' - 10);
152 out[i * 2 + 1] = (j +
'0');
154 out[i * 2 + 1] = (j +
'a' - 10);
157 out[datalen * 2] = 0;
162 string DSL_CC
bin2hex(
const uint8_t * data,
size_t datalen) {
164 size_t len = (datalen * 2) + 1;
165 char * tmp = (
char *)dsl_malloc(len);
166 if (
bin2hex(data, datalen, tmp, len)) {
173 inline uint8 hex_digit_value(uint8 c) {
174 if (c >=
'0' && c <=
'9') {
176 }
else if (c >=
'a' && c <=
'f') {
177 return (c -
'a') + 10;
178 }
else if (c >=
'A' && c <=
'F') {
179 return (c -
'A') + 10;
184 bool DSL_CC
hex2bin(
const char * in,
size_t len, uint8 * out,
size_t outsize) {
185 if ((len % 2) == 0 && outsize >= len / 2) {
187 for (
size_t i = 0; i < len / 2 && *p != 0; i++, out++) {
188 uint8 val = hex_digit_value(*p++);
189 if (val == 0xFF) {
return false; }
190 *out = (val << 4) & 0xF0;
191 val = hex_digit_value(*p++);
192 if (val == 0xFF) {
return false; }
198 memset(out, 0, outsize);
202 bool DSL_CC
hex2bin(
const char * in, uint8 * out,
size_t outsize) {
203 size_t len = strlen(in);
204 return hex2bin(in, len, out, outsize);
207 bool DSL_CC
hex2bin(
const string str, vector<uint8_t>& bin) {
208 if (str.length() % 2 != 0) {
211 size_t len = str.length() / 2;
213 return hex2bin(str.c_str(), str.length(), bin.data(), len);
216 void DSL_CC
PrintData(FILE * fp,
const uint8 * ptr,
size_t len) {
217 unsigned int step = 0;
218 for (
size_t beg = 0; beg < len; beg += 16) {
219 size_t tostep = ((len - beg) >= 16) ? 16 : (len - beg);
221 fprintf(fp,
"%08zxh: ", beg);
223 for (step = 0; step < tostep; step++) {
224 fprintf(fp,
"%02X ", ptr[beg + step] & 0xFF);
231 for (step = 0; step < tostep; step++) {
232 char c = ptr[beg + step] & 0xFF;
233 if (c < 32) { c =
'.'; }
234 fprintf(fp,
"%c", c);
248 const char *p = strrchr(fn,
'\\');
249 if (!p) { p = strrchr(fn,
'/'); }
251 const char *p = strrchr(fn,
'/');
252 if (!p) { p = strrchr(fn,
'\\'); }
254 if (p) {
return ++p; }
260 char *p = strrchr(fn,
'\\');
261 if (!p) { p = strrchr(fn,
'/'); }
263 char *p = strrchr(fn,
'/');
264 if (!p) { p = strrchr(fn,
'\\'); }
266 if (p) {
return ++p; }
270 const wchar_t * DSL_CC
nopathW(
const wchar_t *fn) {
272 const wchar_t *p = wcsrchr(fn,
'\\');
273 if (!p) { p = wcsrchr(fn,
'/'); }
275 const wchar_t *p = wcsrchr(fn,
'/');
276 if (!p) { p = wcsrchr(fn,
'\\'); }
278 if (p) {
return ++p; }
284 wchar_t *p = wcsrchr(fn,
'\\');
285 if (!p) { p = wcsrchr(fn,
'/'); }
287 wchar_t *p = wcsrchr(fn,
'/');
288 if (!p) { p = wcsrchr(fn,
'\\'); }
290 if (p) {
return ++p; }
294 DSL_API
char * DSL_CC
strtrim(
char *buf,
const char * trim, uint8 sides) {
296 size_t len = strlen(trim);
297 if (sides & TRIM_LEFT) {
298 size_t n = strspn(buf, trim);
300 memmove(buf, buf + n, strlen(buf) - n + 1);
303 if ((sides & TRIM_RIGHT) && buf[0]) {
304 char * p = &buf[strlen(buf)-1];
305 for (i=0; i < len; i++) {
309 if (p < buf) {
break; }
318 char * DSL_CC strtok_r(
char *
string,
const char * delimiters,
char ** save_str) {
321 if (
string == NULL) {
325 string += strspn (
string, delimiters);
333 string = strpbrk (tok, delimiters);
334 if (
string == NULL) {
335 *save_str = strchr(tok, 0);
338 *save_str =
string + 1;
343 const char * DSL_CC stristr(
const char * haystack,
const char * needle) {
344 size_t len = strlen(needle);
346 if (toupper(*haystack) == toupper(*needle)) {
347 if (strnicmp(haystack, needle, len) == 0) {
356 char * DSL_CC stristr(
char * haystack,
const char * needle) {
357 size_t len = strlen(needle);
359 if (toupper(*haystack) == toupper(*needle)) {
360 if (strnicmp(haystack, needle, len) == 0) {
372 for(
char * p = str; *p; p++) {
373 *p = tolower((
unsigned char)*p);
381 if (fullpath == NULL) {
385 char * newdir = dsl_strdup(fullpath);
388 char * q = strchr(p,
':');
394 while (*p == PATH_SEP) {
398 if (newdir[strlen(newdir) - 1] == PATH_SEP) {
400 newdir[strlen(newdir) - 1] = 0;
402 if (access(newdir, F_OK) == 0) {
407 char * tmp = dsl_strdup(fullpath);
408 while ((p = strchr(p, PATH_SEP)) != NULL) {
409 size_t len = p - newdir;
410 strncpy(tmp, newdir, len);
413 if (access(tmp, F_OK) != 0) {
414 dsl_mkdir(tmp, mode);
418 bool ret = (dsl_mkdir(newdir, mode) == 0 || errno == EEXIST);
425 if (p == NULL) {
return true; }
426 return (*p == 0) ?
true:
false;
429 int64 DSL_CC
dsl_clamp(int64 val, int64 vMin, int64 vMax) {
430 return std::min(vMax, std::max(vMin, val));
433 int DSL_CC
wildcmp(
const char *wild,
const char *
string) {
437 const char *cp = NULL, *mp = NULL;
439 while ((*
string) && (*wild !=
'*')) {
440 if ((*wild != *
string) && (*wild !=
'?')) {
454 }
else if ((*wild == *
string) || (*wild ==
'?')) {
463 while (*wild ==
'*') {
469 int DSL_CC
wildicmp(
const char *wild,
const char *
string) {
473 const char *cp = NULL, *mp = NULL;
475 while ((*
string) && (*wild !=
'*')) {
476 if ((tolower(*wild) != tolower(*
string)) && (*wild !=
'?')) {
490 }
else if ((tolower(*wild) == tolower(*
string)) || (*wild ==
'?')) {
499 while (*wild ==
'*') {
505 int DSL_CC
wildicmp_multi(
const char *wild,
const char *
string,
const char *sep) {
507 char * tmp = dsl_strdup((
char *)wild);
509 char * p = strtok_r(tmp, sep, &p2);
512 if (ret != 0) {
break; }
513 p = strtok_r(NULL, sep, &p2);
519 int64 DSL_CC
fseek64(FILE * fp, int64 offset,
int whence) {
521 return _fseeki64(fp, offset, whence);
523 return fseeko(fp, offset, whence);
529 return _ftelli64(fp);
537 if (stat64(fn, &st) == 0) {
544 int DSL_CC truncate(
const char * fn, int64 size) {
545 int fd = open(fn, O_RDWR);
547 int ret = ftruncate(fd, size);
556 memset(out, 0, outSize);
563 while (*p && len < outSize) {
580 const char *p = str.c_str();
592 int DSL_CC
str_replaceA(
char *Str,
size_t BufSize,
const char *FindStr,
const char *ReplStr) {
595 size_t OldLen = strlen(FindStr);
596 size_t NewLen = strlen(ReplStr);
597 while ((p = strstr(Str, FindStr))) {
598 if ((strlen(Str) + NewLen - OldLen) > BufSize) {
601 if (NewLen != OldLen) {
602 memmove(p + NewLen, p + OldLen, strlen(p+OldLen)+1);
604 memcpy(p, ReplStr, NewLen);
611 #if !defined(FREEBSD)
612 int DSL_CC
str_replaceW(
wchar_t * Str,
size_t BufSize,
wchar_t *FindStr,
wchar_t *ReplStr) {
613 wchar_t * p, *End, *Begin;
617 size_t OldLen = wcslen(FindStr);
618 size_t NewLen = wcslen(ReplStr);
619 while ((p = wcsstr(Str, FindStr))) {
620 if ((wcslen(Str) + NewLen - OldLen + 1) > BufSize) {
623 End = dsl_wcsdup(p+OldLen);
624 Begin = dsl_wcsdup(Str);
626 snwprintf(fmt, 32, L
"%%.%zus%%s%%s", len);
627 snwprintf(Str, BufSize, fmt, Begin, ReplStr, End);
636 string DSL_CC
str_replaceA(
const string& src,
const string& FindStr,
const string& ReplStr) {
639 while ((pos = str.find(FindStr)) != str.npos) {
640 str.replace(pos, FindStr.length(), ReplStr);
645 #if !defined(FREEBSD)
646 wstring DSL_CC
str_replaceW(
const wstring& src,
const wstring& FindStr,
const wstring& ReplStr) {
649 while ((pos = str.find(FindStr)) != str.npos) {
650 str.replace(pos, FindStr.length(), ReplStr);
657 char buf[MAX_PATH]={0};
659 char * p = getenv(
"APPDATA");
660 if (p == NULL || *p == 0) {
661 p = getenv(
"USERPROFILE");
663 if (p == NULL || *p == 0) {
664 GetModuleFileNameA(NULL, buf,
sizeof(buf));
665 char * q = strrchr(buf,
'\\');
673 char * p = getenv(
"HOME");
676 }
else if (getcwd(buf,
sizeof(buf)) == NULL) {
680 if (buf[strlen(buf)-1] != PATH_SEP) {
688 if (stat(buf, &st) != 0) {
689 dsl_mkdir(buf, 0700);
691 strcat(buf, PATH_SEPS);
692 return dsl_strdup(buf);
711 string ret =
mprintf(
"%s%s", dir, fn.c_str());
717 wchar_t buf[MAX_PATH]={0};
719 wchar_t * p = wgetenv(L
"APPDATA");
720 if (!p || !wcslen(p)) {
721 p = wgetenv(L
"USERPROFILE");
723 if (!p || !wcslen(p)) {
724 GetModuleFileNameW(NULL, buf,
sizeof(buf));
725 wchar_t * q = wcsrchr(buf,
'\\');
743 if (buf[wcslen(buf)-1] != PATH_SEP) {
744 wcscat(buf, WPATH_SEPS);
746 return dsl_wcsdup(buf);
757 char buf[MAX_PATH] = { 0 };
759 char * p = getenv(
"USERPROFILE");
760 if (p == NULL || *p == 0) {
761 GetModuleFileNameA(NULL, buf,
sizeof(buf));
762 char * q = strrchr(buf,
'\\');
770 char * p = getenv(
"HOME");
773 }
else if (getcwd(buf,
sizeof(buf)) == NULL) {
777 if (buf[strlen(buf) - 1] != PATH_SEP) {
780 sstrcat(buf,
"Documents" PATH_SEPS
"");
783 if (stat(buf, &st) != 0) {
784 dsl_mkdir(buf, 0700);
786 strcat(buf, PATH_SEPS);
787 return dsl_strdup(buf);
796 static timeval tv_start = {0,0};
797 if (tv_start.tv_sec == 0) {
798 gettimeofday (&tv_start, NULL);
799 tv_start.tv_usec = 0;
803 gettimeofday(&tv, NULL);
804 uint64 ret = uint64(tv.tv_sec - tv_start.tv_sec) * 1000;
805 ret += uint64(tv.tv_usec / 1000);
811 DSL_API
char * DSL_CC tcstombsA(
const char * str) {
812 return dsl_strdup(str);
815 DSL_API
char * DSL_CC tcstombsW(
const wchar_t * str) {
816 size_t len = wcstombs(NULL, str, 0);
817 if (len == (
size_t)-1) {
818 return dsl_strdup(
"ERROR in wcstombs");
820 char * buf = (
char *)dsl_malloc(len+1);
822 wcstombs(buf, str, len);
826 DSL_API
wchar_t * DSL_CC tcstowcsW(
const wchar_t * str) {
827 return dsl_wcsdup(str);
829 DSL_API
wchar_t * DSL_CC tcstowcsA(
const char * str) {
830 size_t len = mbstowcs(NULL, str, 0);
831 if (len == (
size_t)-1) {
832 return dsl_wcsdup(L
"ERROR in mbstowcs");
834 size_t llen = (len+1)*
sizeof(
wchar_t);
835 wchar_t * buf = (
wchar_t *)dsl_malloc(llen);
836 memset(buf, 0, llen);
837 mbstowcs(buf, str, len);
841 DSL_API
char * DSL_CC mbstotcsA(
const char * str) {
842 return dsl_strdup(str);
844 DSL_API
char * DSL_CC wcstotcsA(
const wchar_t * str) {
845 size_t len = wcstombs(NULL, str, 0);
846 if (len == (
size_t)-1) {
847 return dsl_strdup(
"ERROR in wcstombs");
849 char * buf = (
char *)dsl_malloc(len+1);
851 wcstombs(buf, str, len);
855 DSL_API
wchar_t * DSL_CC mbstotcsW(
const char * str) {
856 size_t len = mbstowcs(NULL, str, 0);
857 if (len == (
size_t)-1) {
858 return dsl_wcsdup(L
"ERROR in mbstowcs");
860 size_t llen = (len+1)*
sizeof(
wchar_t);
861 wchar_t * buf = (
wchar_t *)dsl_malloc(llen);
862 memset(buf, 0, llen);
863 mbstowcs(buf, str, len);
867 DSL_API
wchar_t * DSL_CC wcstotcsW(
const wchar_t * str) {
868 return dsl_wcsdup(str);
871 DSL_API
size_t DSL_CC wcscnt(
const wchar_t * ptr) {
874 n +=
sizeof(
wchar_t);
878 #if !defined(HAVE_STRLCPY)
879 DSL_API
size_t DSL_CC
strlcat(
char *dst,
const char *src,
size_t siz) {
886 while (n-- != 0 && *d !=
'\0')
892 return(dlen + strlen(s));
902 return(dlen + (s - src));
905 DSL_API
size_t DSL_CC
strlcpy(
char *dst,
const char *src,
size_t siz)
914 if ((*d++ = *s++) ==
'\0')
932 DSL_API
wchar_t * DSL_CC wcsdup(
const wchar_t *s) {
933 size_t len = (wcscnt(s) + 1) *
sizeof(
wchar_t);
934 wchar_t * copy = (
wchar_t *)malloc(len);
935 if (copy == NULL) {
return NULL; }
936 memcpy(copy, s, len);
942 struct tm * DSL_CC localtime_r(
const time_t * tme,
struct tm * out) {
943 if (!tme || !out)
return NULL;
944 if (localtime_s(out, tme) != 0) {
945 memset(out, 0,
sizeof(
struct tm));
949 struct tm * DSL_CC gmtime_r(
const time_t * tme,
struct tm * out) {
950 if (!tme || !out)
return NULL;
951 if (gmtime_s(out, tme) != 0) {
952 memset(out, 0,
sizeof(
struct tm));
958 inline bool _file_get_contents_begin(
const string& fn, int64 maxSize, int64& len, FILE ** fp) {
959 *fp = fopen(fn.c_str(),
"rb");
965 if (len > maxSize || len < 0) {
972 DSL_API_CLASS
bool DSL_CC
file_get_contents(
const string& fn, vector<uint8>& data, int64 maxSize) {
975 if (!_file_get_contents_begin(fn, maxSize, len, &fp)) {
980 bool ret = (fread(data.data(), len, 1, fp) == 1);
988 if (!_file_get_contents_begin(fn, maxSize, len, &fp)) {
993 bool ret = (fread(&data[0], len, 1, fp) == 1);
998 DSL_API_CLASS
bool DSL_CC
file_get_contents(
const string& fn, uint8 ** data, int64& len, int64 maxSize) {
1000 if (!_file_get_contents_begin(fn, maxSize, len, &fp)) {
1004 *data = (uint8 *)dsl_malloc(len);
1005 if (*data == NULL) {
1008 bool ret = (fread(*data, len, 1, fp) == 1);
1017 bool DSL_CC file_put_contents(
const string& fn,
const vector<uint8>& data,
bool append) {
1018 FILE * fp = fopen(fn.c_str(), append ?
"ab" :
"wb");
1023 bool ret = (fwrite(data.data(), data.size(), 1, fp) == 1);
1028 bool DSL_CC file_put_contents(
const string& fn,
const string& data,
bool append) {
1029 FILE * fp = fopen(fn.c_str(), append ?
"ab" :
"wb");
1034 bool ret = (fwrite(data.c_str(), data.length(), 1, fp) == 1);
1039 bool DSL_CC file_put_contents(
const string& fn,
const uint8 * data,
size_t fileSize,
bool append) {
1040 FILE * fp = fopen(fn.c_str(), append ?
"ab" :
"wb");
1045 bool ret = (fwrite(data, fileSize, 1, fp) == 1);
1050 int64 DSL_CC
copy_file(
const string& src,
const string& dest,
bool allow_overwrite) {
1053 if (ret >= 0 && CopyFile(src.c_str(), dest.c_str(), !allow_overwrite)) {
1058 int fdi = open(src.c_str(), O_RDONLY);
1063 int flags = O_WRONLY | O_CREAT;
1064 if (allow_overwrite) {
1069 int fdo = open(dest.c_str(), flags);
1076 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 27))
1077 ret = copy_file_range(fdi, NULL, fdo, NULL, SIZE_MAX, 0);
1081 while ((n = read(fdi, buf,
sizeof(buf))) > 0) {
1082 if (write(fdo, buf, n) != n) {
1102 return ( ((X >> 8)) | (X << 8) );
1106 return( (X<<24) | ((X<<8) & 0x00FF0000) | ((X>>8) & 0x0000FF00) | (X>>24) );
1110 uint32 lo = (uint32)(val&0xFFFFFFFF);
1112 uint32 hi = (uint32)(val&0xFFFFFFFF);
1119 #ifdef LITTLE_ENDIAN
1120 DSL_API uint16 DSL_CC
Get_ULE16(uint16 x) {
return(x); }
1121 DSL_API int16 DSL_CC
Get_SLE16(int16 x) {
return(x); }
1122 DSL_API uint32 DSL_CC
Get_ULE32(uint32 x) {
return(x); }
1123 DSL_API int32 DSL_CC
Get_SLE32(int32 x) {
return(x); }
1124 DSL_API uint64 DSL_CC
Get_ULE64(uint64 x) {
return(x); }
1125 DSL_API int64 DSL_CC
Get_SLE64(int64 x) {
return(x); }
1150 return (FirstInvalidUTF8(s) == NULL);
1153 DSL_API
const char * DSL_CC FirstInvalidUTF8(
const char *p) {
1154 const uint8 *s = (
const uint8 *)p;
1159 else if ((s[0] & 0xe0) == 0xc0) {
1161 if ((s[1] & 0xc0) != 0x80 ||
1162 (s[0] & 0xfe) == 0xc0)
1166 }
else if ((s[0] & 0xf0) == 0xe0) {
1168 if ((s[1] & 0xc0) != 0x80 ||
1169 (s[2] & 0xc0) != 0x80 ||
1170 (s[0] == 0xe0 && (s[1] & 0xe0) == 0x80) ||
1171 (s[0] == 0xed && (s[1] & 0xe0) == 0xa0) ||
1172 (s[0] == 0xef && s[1] == 0xbf &&
1173 (s[2] & 0xfe) == 0xbe))
1177 }
else if ((s[0] & 0xf8) == 0xf0) {
1179 if ((s[1] & 0xc0) != 0x80 ||
1180 (s[2] & 0xc0) != 0x80 ||
1181 (s[3] & 0xc0) != 0x80 ||
1182 (s[0] == 0xf0 && (s[1] & 0xf0) == 0x80) ||
1183 (s[0] == 0xf4 && s[1] > 0x8f) || s[0] > 0xf4)
void FreeString(char *buf)
You must call this on any string returned by GetTok/GetSingleTok.
StrTokenizer(char *str, char separater, bool do_strdup=true)
DSL_API uint64 DSL_CC Get_ULE64(uint64 x)
Convert from the native endianness to Little Endian.
DSL_API int64 DSL_CC Get_SBE64(int64 x)
Convert from the native endianness to Big Endian.
DSL_API uint16 DSL_CC ByteSwap16(uint16 X)
Byte swap a 16-bit unsigned integer.
DSL_API int32 DSL_CC Get_SBE32(int32 x)
Convert from the native endianness to Big Endian.
DSL_API int32 DSL_CC Get_SLE32(int32 x)
Convert from the native endianness to Little Endian.
DSL_API uint16 DSL_CC Get_UBE16(uint16 x)
Convert from the native endianness to Big Endian.
DSL_API uint64 DSL_CC ByteSwap64(uint64 val)
Byte swap a 64-bit unsigned integer.
DSL_API int16 DSL_CC Get_SBE16(int16 x)
Convert from the native endianness to Big Endian.
DSL_API uint32 DSL_CC Get_ULE32(uint32 x)
Convert from the native endianness to Little Endian.
DSL_API int16 DSL_CC Get_SLE16(int16 x)
Convert from the native endianness to Little Endian.
DSL_API uint32 DSL_CC Get_UBE32(uint32 x)
Convert from the native endianness to Big Endian.
DSL_API uint32 DSL_CC ByteSwap32(uint32 X)
Byte swap a 32-bit unsigned integer.
DSL_API uint64 DSL_CC Get_UBE64(uint64 x)
Convert from the native endianness to Big Endian.
DSL_API uint16 DSL_CC Get_ULE16(uint16 x)
Convert from the native endianness to Little Endian.
DSL_API int64 DSL_CC Get_SLE64(int64 x)
Convert from the native endianness to Little Endian.
DSL_API_CLASS string mprintf(const string fmt,...)
DSL_API wchar_t *DSL_CC dsl_wmprintf(const wchar_t *fmt,...)
DSL_API void DSL_CC dsl_free(void *ptr)
DSL_API char *DSL_CC dsl_mprintf(const char *fmt,...)
char *DSL_CC strlwr(char *str)
Linux version of strlwr.
DSL_API uint64 DSL_CC GetTickCount64()
Linux version of GetTickCount64.
DSL_API bool DSL_CC IsValidUTF8(const char *s)
Checks if the string is valid UTF-8 (no invalid UTF-8 sequences, etc.)
int64 DSL_CC copy_file(const string &src, const string &dest, bool allow_overwrite)
DSL_API size_t DSL_CC strlcpy(char *dst, const char *src, size_t siz)
char *DSL_CC bin2hex(const uint8_t *data, size_t datalen, char *out, size_t outsize)
bool DSL_CC hex2bin(const char *in, size_t len, uint8 *out, size_t outsize)
bool DSL_CC dsl_mkdir_r(const char *fullpath, int mode)
Cross-platform recursive mkdir()
wchar_t *DSL_CC GetUserConfigFolderW(const wchar_t *name)
Unicode version of...
bool DSL_CC strempty(const char *p)
Returns true if a string is empty (p == NULL || *p == 0)
int DSL_CC str_replaceA(char *Str, size_t BufSize, const char *FindStr, const char *ReplStr)
Simple string replacement.
void DSL_CC PrintData(FILE *fp, const uint8 *ptr, size_t len)
Prints binary data in a pretty format.
const char *DSL_CC nopathA(const char *fn)
Returns just the file portion of the full path and filename.
int64 DSL_CC ftell64(FILE *fp)
Cross-platform 64-bit ftell.
char *DSL_CC GetUserConfigFileA(const char *name, const char *fn)
char *DSL_CC GetUserConfigFolderA(const char *name)
DSL_API size_t DSL_CC strlcat(char *dst, const char *src, size_t siz)
const wchar_t *DSL_CC nopathW(const wchar_t *fn)
Returns just the file portion of the full path and filename.
int DSL_CC wildicmp(const char *wild, const char *string)
int DSL_CC wildcmp(const char *wild, const char *string)
wstring DSL_CC str_replaceW(const wstring &src, const wstring &FindStr, const wstring &ReplStr)
Simple string replacement.
char *DSL_CC GetUserDocumentsFolderA(const char *name)
int64 DSL_CC filesize(const char *fn)
Get the size in bytes of a file.
int64 DSL_CC fseek64(FILE *fp, int64 offset, int whence)
Cross-platform 64-bit fseek.
DSL_API char *DSL_CC strtrim(char *buf, const char *trim, uint8 sides)
int DSL_CC wildicmp_multi(const char *wild, const char *string, const char *sep)
wchar_t *DSL_CC GetUserConfigFileW(const wchar_t *name, const wchar_t *fn)
Unicode version of...
char *DSL_CC escapeshellarg(const char *p, char *out, size_t outSize)
Escapes an argument for passing to shell functions, only escapes quotes atm so keep that in mind.
DSL_API_CLASS bool DSL_CC file_get_contents(const string &fn, vector< uint8 > &data, int64 maxSize)
DSL_API uint32 DSL_CC GetTickCount()
Linux version of GetTickCount.
int64 DSL_CC dsl_clamp(int64 val, int64 vMin, int64 vMax)
Clamps a given value to the range of vMin to vMax (inclusive)