mirror of
https://github.com/decompals/wibo.git
synced 2025-10-16 07:05:11 +00:00
more wstr funcs
This commit is contained in:
parent
da17dd573d
commit
f45dd85be3
@ -1,5 +1,6 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
#include <cwctype>
|
#include <cwctype>
|
||||||
@ -117,6 +118,10 @@ namespace msvcrt {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* WIN_ENTRY getenv(const char *varname){
|
||||||
|
return std::getenv(varname);
|
||||||
|
}
|
||||||
|
|
||||||
char* WIN_ENTRY setlocale(int category, const char *locale){
|
char* WIN_ENTRY setlocale(int category, const char *locale){
|
||||||
return std::setlocale(category, locale);
|
return std::setlocale(category, locale);
|
||||||
}
|
}
|
||||||
@ -151,6 +156,34 @@ namespace msvcrt {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WIN_ENTRY _wgetenv_s(size_t* pReturnValue, uint16_t* buffer, size_t numberOfElements, const uint16_t* varname){
|
||||||
|
std::string var_str = wideStringToString(varname);
|
||||||
|
DEBUG_LOG("_wgetenv_s: var name %s\n", var_str.c_str());
|
||||||
|
if(!buffer || !varname) return 22;
|
||||||
|
|
||||||
|
size_t varnamelen = wstrlen(varname);
|
||||||
|
|
||||||
|
for(uint16_t** env = __winitenv; env && *env; ++env){
|
||||||
|
uint16_t* cur = *env;
|
||||||
|
std::string cur_str = wideStringToString(cur);
|
||||||
|
if(wstrncmp(cur, varname, varnamelen) == 0 && cur[varnamelen] == L'='){
|
||||||
|
uint16_t* value = cur + varnamelen + 1;
|
||||||
|
size_t value_len = wstrlen(value);
|
||||||
|
|
||||||
|
size_t copy_len = (value_len < numberOfElements - 1) ? value_len : numberOfElements - 1;
|
||||||
|
wstrncpy(buffer, value, copy_len);
|
||||||
|
buffer[copy_len] = 0;
|
||||||
|
|
||||||
|
if(pReturnValue) *pReturnValue = value_len + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = 0;
|
||||||
|
if(pReturnValue) *pReturnValue = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void* WIN_ENTRY malloc(size_t size){
|
void* WIN_ENTRY malloc(size_t size){
|
||||||
return std::malloc(size);
|
return std::malloc(size);
|
||||||
}
|
}
|
||||||
@ -371,10 +404,18 @@ namespace msvcrt {
|
|||||||
return wstrstr(dest, src);
|
return wstrstr(dest, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WIN_ENTRY iswspace(wint_t w){
|
int WIN_ENTRY iswspace(uint32_t w){
|
||||||
return std::iswspace(w);
|
return std::iswspace(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WIN_ENTRY iswdigit(uint32_t w){
|
||||||
|
return std::iswdigit(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint16_t* WIN_ENTRY wcschr(const uint16_t* str, uint16_t c){
|
||||||
|
return wstrchr(str, c);
|
||||||
|
}
|
||||||
|
|
||||||
const uint16_t* WIN_ENTRY wcsrchr(const uint16_t *str, uint16_t c){
|
const uint16_t* WIN_ENTRY wcsrchr(const uint16_t *str, uint16_t c){
|
||||||
return wstrrchr(str, c);
|
return wstrrchr(str, c);
|
||||||
}
|
}
|
||||||
@ -421,6 +462,10 @@ static void *resolveByName(const char *name) {
|
|||||||
if (strcmp(name, "iswspace") == 0) return (void*)msvcrt::iswspace;
|
if (strcmp(name, "iswspace") == 0) return (void*)msvcrt::iswspace;
|
||||||
if (strcmp(name, "wcsrchr") == 0) return (void*)msvcrt::wcsrchr;
|
if (strcmp(name, "wcsrchr") == 0) return (void*)msvcrt::wcsrchr;
|
||||||
if (strcmp(name, "wcstoul") == 0) return (void*)msvcrt::wcstoul;
|
if (strcmp(name, "wcstoul") == 0) return (void*)msvcrt::wcstoul;
|
||||||
|
if (strcmp(name, "iswdigit") == 0) return (void*)msvcrt::iswdigit;
|
||||||
|
if (strcmp(name, "wcschr") == 0) return (void*)msvcrt::wcschr;
|
||||||
|
if (strcmp(name, "getenv") == 0) return (void*)msvcrt::getenv;
|
||||||
|
if (strcmp(name, "_wgetenv_s") == 0) return (void*)msvcrt::_wgetenv_s;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
strutil.cpp
13
strutil.cpp
@ -50,6 +50,19 @@ const uint16_t* wstrstr(const uint16_t *dest, const uint16_t *src){
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t* wstrchr(const uint16_t* str, uint16_t c) {
|
||||||
|
for (; *str != 0; str++) {
|
||||||
|
if (*str == c) {
|
||||||
|
return (uint16_t*)str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If searching for '\0', return pointer to terminator
|
||||||
|
if (c == 0) {
|
||||||
|
return (uint16_t*)str;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t* wstrrchr(const uint16_t* str, uint16_t c){
|
uint16_t* wstrrchr(const uint16_t* str, uint16_t c){
|
||||||
const uint16_t* last = nullptr;
|
const uint16_t* last = nullptr;
|
||||||
for (; *str != 0; str++) {
|
for (; *str != 0; str++) {
|
||||||
|
@ -5,6 +5,7 @@ size_t wstrlen(const uint16_t *str);
|
|||||||
size_t wstrnlen(const uint16_t* str, size_t numberOfElements);
|
size_t wstrnlen(const uint16_t* str, size_t numberOfElements);
|
||||||
int wstrncmp(const uint16_t *string1, const uint16_t *string2, size_t count);
|
int wstrncmp(const uint16_t *string1, const uint16_t *string2, size_t count);
|
||||||
const uint16_t* wstrstr(const uint16_t *dest, const uint16_t *src);
|
const uint16_t* wstrstr(const uint16_t *dest, const uint16_t *src);
|
||||||
|
uint16_t* wstrchr(const uint16_t* str, uint16_t c);
|
||||||
uint16_t* wstrrchr(const uint16_t* str, uint16_t c);
|
uint16_t* wstrrchr(const uint16_t* str, uint16_t c);
|
||||||
uint16_t* wstrcat(uint16_t* dest, const uint16_t* src);
|
uint16_t* wstrcat(uint16_t* dest, const uint16_t* src);
|
||||||
uint16_t* wstrncat(uint16_t* dest, const uint16_t* src, size_t count);
|
uint16_t* wstrncat(uint16_t* dest, const uint16_t* src, size_t count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user