Added _wcsnlen function for WCHAR string length.

This commit is contained in:
Armin Novak 2018-12-10 12:39:32 +01:00
parent 97c5210dbc
commit 1e644fc37e
2 changed files with 46 additions and 25 deletions

View File

@ -58,6 +58,8 @@ WINPR_API int _strnicmp(const char* string1, const char* string2, size_t count);
WINPR_API int _wcscmp(const WCHAR* string1, const WCHAR* string2);
WINPR_API size_t _wcslen(const WCHAR* str);
WINPR_API size_t _wcsnlen(const WCHAR* str, size_t numberOfElements);
WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
WINPR_API WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);

View File

@ -104,7 +104,7 @@ int _wcscmp(const WCHAR* string1, const WCHAR* string2)
size_t _wcslen(const WCHAR* str)
{
WCHAR* p = (WCHAR*) str;
const WCHAR* p = (const WCHAR*) str;
if (!p)
return 0;
@ -112,17 +112,36 @@ size_t _wcslen(const WCHAR* str)
while (*p)
p++;
return (p - str);
return (size_t)(p - str);
}
/* _wcsnlen -> wcsnlen */
size_t _wcsnlen(const WCHAR* str, size_t max)
{
size_t x;
if (!str)
return 0;
for (x = 0; x < max; x++)
{
if (str[x] == 0)
return x;
}
return x;
}
/* _wcschr -> wcschr */
WCHAR* _wcschr(const WCHAR* str, WCHAR c)
{
WCHAR* p = (WCHAR*) str;
WCHAR value;
Data_Write_UINT16(&value, c);
while (*p && (*p != value))
p++;
@ -160,6 +179,7 @@ WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
strToken = *context;
Data_Read_UINT16(strToken, value);
while (*strToken && _wcschr(strDelimit, value))
{
strToken++;
@ -170,8 +190,8 @@ WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
return NULL;
nextToken = strToken++;
Data_Read_UINT16(strToken, value);
while (*strToken && !(_wcschr(strDelimit, value)))
{
strToken++;
@ -440,7 +460,6 @@ int ConvertLineEndingToLF(char* str, int size)
char* end;
char* pInput;
char* pOutput;
end = &str[size];
pInput = pOutput = str;
@ -458,7 +477,6 @@ int ConvertLineEndingToLF(char* str, int size)
}
status = (int)(pOutput - str);
return status;
}
@ -469,9 +487,7 @@ char* ConvertLineEndingToCRLF(const char* str, int* size)
char* pOutput;
const char* end;
const char* pInput;
end = &str[*size];
count = 0;
pInput = str;
@ -507,7 +523,6 @@ char* ConvertLineEndingToCRLF(const char* str, int* size)
}
*size = (int)(pOutput - newStr);
return newStr;
}
@ -515,7 +530,6 @@ char* StrSep(char** stringp, const char* delim)
{
char* start = *stringp;
char* p;
p = (start != NULL) ? strpbrk(start, delim) : NULL;
if (!p)
@ -549,18 +563,23 @@ INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
{
*size += step;
n = realloc(*lineptr, *size);
if (!n)
{
return -1;
}
*lineptr = n;
}
c = fgetc(stream);
if (c != EOF)
(*lineptr)[used++] = c;
} while((c != '\n') && (c != '\r') && (c != EOF));
(*lineptr)[used] = '\0';
}
while ((c != '\n') && (c != '\r') && (c != EOF));
(*lineptr)[used] = '\0';
return used;
#elif !defined(ANDROID) && !defined(IOS)
return getline(lineptr, size, stream);