Blame winpr/libwinpr/crt/string.c

Packit Service fa4841
/**
Packit Service fa4841
 * WinPR: Windows Portable Runtime
Packit Service fa4841
 * String Manipulation (CRT)
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef HAVE_CONFIG_H
Packit Service fa4841
#include "config.h"
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#include <errno.h>
Packit Service fa4841
#include <stdio.h>
Packit Service fa4841
#include <wctype.h>
Packit Service fa4841
Packit Service fa4841
#include <winpr/crt.h>
Packit Service fa4841
#include <winpr/endian.h>
Packit Service fa4841
Packit Service fa4841
/* String Manipulation (CRT): http://msdn.microsoft.com/en-us/library/f0151s4x.aspx */
Packit Service fa4841
Packit Service fa4841
#include "../log.h"
Packit Service fa4841
#define TAG WINPR_TAG("crt")
Packit Service fa4841
Packit Service fa4841
#ifndef _WIN32
Packit Service fa4841
Packit Service fa4841
char* _strdup(const char* strSource)
Packit Service fa4841
{
Packit Service fa4841
	char* strDestination;
Packit Service fa4841
Packit Service fa4841
	if (strSource == NULL)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service fa4841
	strDestination = strdup(strSource);
Packit Service fa4841
Packit Service fa4841
	if (strDestination == NULL)
Packit Service b1ea74
		WLog_ERR(TAG, "strdup");
Packit Service fa4841
Packit Service fa4841
	return strDestination;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WCHAR* _wcsdup(const WCHAR* strSource)
Packit Service fa4841
{
Packit Service fa4841
	WCHAR* strDestination;
Packit Service fa4841
Packit Service fa4841
	if (strSource == NULL)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service fa4841
#if defined(__APPLE__) && defined(__MACH__) || defined(ANDROID) || defined(sun)
Packit Service fa4841
	strDestination = malloc(wcslen((wchar_t*)strSource));
Packit Service fa4841
Packit Service fa4841
	if (strDestination != NULL)
Packit Service fa4841
		wcscpy((wchar_t*)strDestination, (const wchar_t*)strSource);
Packit Service fa4841
Packit Service fa4841
#else
Packit Service b1ea74
	strDestination = (WCHAR*)wcsdup((wchar_t*)strSource);
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
	if (strDestination == NULL)
Packit Service b1ea74
		WLog_ERR(TAG, "wcsdup");
Packit Service fa4841
Packit Service fa4841
	return strDestination;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int _stricmp(const char* string1, const char* string2)
Packit Service fa4841
{
Packit Service fa4841
	return strcasecmp(string1, string2);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int _strnicmp(const char* string1, const char* string2, size_t count)
Packit Service fa4841
{
Packit Service fa4841
	return strncasecmp(string1, string2, count);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* _wcscmp -> wcscmp */
Packit Service fa4841
Packit Service fa4841
int _wcscmp(const WCHAR* string1, const WCHAR* string2)
Packit Service fa4841
{
Packit Service fa4841
	WCHAR value1, value2;
Packit Service fa4841
Packit Service fa4841
	while (*string1 && (*string1 == *string2))
Packit Service fa4841
	{
Packit Service fa4841
		string1++;
Packit Service fa4841
		string2++;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	Data_Read_UINT16(string1, value1);
Packit Service fa4841
	Data_Read_UINT16(string2, value2);
Packit Service fa4841
	return value1 - value2;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* _wcslen -> wcslen */
Packit Service fa4841
Packit Service fa4841
size_t _wcslen(const WCHAR* str)
Packit Service fa4841
{
Packit Service b1ea74
	const WCHAR* p = (const WCHAR*)str;
Packit Service fa4841
Packit Service fa4841
	if (!p)
Packit Service fa4841
		return 0;
Packit Service fa4841
Packit Service fa4841
	while (*p)
Packit Service fa4841
		p++;
Packit Service fa4841
Packit Service b1ea74
	return (size_t)(p - str);
Packit Service b1ea74
}
Packit Service b1ea74
Packit Service b1ea74
/* _wcsnlen -> wcsnlen */
Packit Service b1ea74
Packit Service b1ea74
size_t _wcsnlen(const WCHAR* str, size_t max)
Packit Service b1ea74
{
Packit Service b1ea74
	size_t x;
Packit Service b1ea74
Packit Service b1ea74
	if (!str)
Packit Service b1ea74
		return 0;
Packit Service b1ea74
Packit Service b1ea74
	for (x = 0; x < max; x++)
Packit Service b1ea74
	{
Packit Service b1ea74
		if (str[x] == 0)
Packit Service b1ea74
			return x;
Packit Service b1ea74
	}
Packit Service b1ea74
Packit Service b1ea74
	return x;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* _wcschr -> wcschr */
Packit Service fa4841
Packit Service fa4841
WCHAR* _wcschr(const WCHAR* str, WCHAR c)
Packit Service fa4841
{
Packit Service b1ea74
	WCHAR* p = (WCHAR*)str;
Packit Service fa4841
	WCHAR value;
Packit Service bb5c11
	Data_Write_UINT16(&value, c);
Packit Service b1ea74
Packit Service fa4841
	while (*p && (*p != value))
Packit Service fa4841
		p++;
Packit Service fa4841
Packit Service fa4841
	return ((*p == value) ? p : NULL);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/* _wcsrchr -> wcsrchr */
Packit Service fa4841
Packit Service fa4841
WCHAR* _wcsrchr(const WCHAR* str, WCHAR c)
Packit Service fa4841
{
Packit Service b1ea74
	WCHAR* p;
Packit Service fa4841
	WCHAR ch;
Packit Service fa4841
Packit Service fa4841
	if (!str)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service b1ea74
	for (p = (WCHAR*)0; (ch = *str); str++)
Packit Service fa4841
		if (ch == c)
Packit Service b1ea74
			p = (WCHAR*)str;
Packit Service fa4841
Packit Service fa4841
	return p;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
char* strtok_s(char* strToken, const char* strDelimit, char** context)
Packit Service fa4841
{
Packit Service fa4841
	return strtok_r(strToken, strDelimit, context);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
Packit Service fa4841
{
Packit Service fa4841
	WCHAR* nextToken;
Packit Service fa4841
	WCHAR value;
Packit Service fa4841
Packit Service fa4841
	if (!strToken)
Packit Service fa4841
		strToken = *context;
Packit Service fa4841
Packit Service fa4841
	Data_Read_UINT16(strToken, value);
Packit Service b1ea74
Packit Service fa4841
	while (*strToken && _wcschr(strDelimit, value))
Packit Service fa4841
	{
Packit Service fa4841
		strToken++;
Packit Service fa4841
		Data_Read_UINT16(strToken, value);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	if (!*strToken)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service fa4841
	nextToken = strToken++;
Packit Service bb5c11
	Data_Read_UINT16(strToken, value);
Packit Service b1ea74
Packit Service fa4841
	while (*strToken && !(_wcschr(strDelimit, value)))
Packit Service fa4841
	{
Packit Service fa4841
		strToken++;
Packit Service fa4841
		Data_Read_UINT16(strToken, value);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	if (*strToken)
Packit Service fa4841
		*strToken++ = 0;
Packit Service fa4841
Packit Service fa4841
	*context = strToken;
Packit Service fa4841
	return nextToken;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#if !defined(_WIN32) || defined(_UWP)
Packit Service fa4841
Packit Service fa4841
/* Windows API Sets - api-ms-win-core-string-l2-1-0.dll
Packit Service fa4841
 * http://msdn.microsoft.com/en-us/library/hh802935/
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#include "casing.c"
Packit Service fa4841
Packit Service fa4841
LPSTR CharUpperA(LPSTR lpsz)
Packit Service fa4841
{
Packit Service b1ea74
	size_t i;
Packit Service b1ea74
	size_t length;
Packit Service fa4841
Packit Service fa4841
	if (!lpsz)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service b1ea74
	length = strlen(lpsz);
Packit Service fa4841
Packit Service fa4841
	if (length < 1)
Packit Service b1ea74
		return (LPSTR)NULL;
Packit Service fa4841
Packit Service fa4841
	if (length == 1)
Packit Service fa4841
	{
Packit Service fa4841
		char c = *lpsz;
Packit Service fa4841
Packit Service fa4841
		if ((c >= 'a') && (c <= 'z'))
Packit Service fa4841
			c = c - 32;
Packit Service fa4841
Packit Service fa4841
		*lpsz = c;
Packit Service fa4841
		return lpsz;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < length; i++)
Packit Service fa4841
	{
Packit Service fa4841
		if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
Packit Service fa4841
			lpsz[i] = lpsz[i] - 32;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return lpsz;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LPWSTR CharUpperW(LPWSTR lpsz)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "CharUpperW unimplemented!");
Packit Service b1ea74
	return (LPWSTR)NULL;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
Packit Service fa4841
{
Packit Service fa4841
	DWORD i;
Packit Service fa4841
Packit Service fa4841
	if (cchLength < 1)
Packit Service fa4841
		return 0;
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < cchLength; i++)
Packit Service fa4841
	{
Packit Service fa4841
		if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
Packit Service fa4841
			lpsz[i] = lpsz[i] - 32;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return cchLength;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength)
Packit Service fa4841
{
Packit Service fa4841
	DWORD i;
Packit Service fa4841
	WCHAR value;
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < cchLength; i++)
Packit Service fa4841
	{
Packit Service fa4841
		Data_Read_UINT16(&lpsz[i], value);
Packit Service fa4841
		value = WINPR_TOUPPERW(value);
Packit Service fa4841
		Data_Write_UINT16(&lpsz[i], value);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return cchLength;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LPSTR CharLowerA(LPSTR lpsz)
Packit Service fa4841
{
Packit Service b1ea74
	size_t i;
Packit Service b1ea74
	size_t length;
Packit Service fa4841
Packit Service fa4841
	if (!lpsz)
Packit Service b1ea74
		return (LPSTR)NULL;
Packit Service fa4841
Packit Service b1ea74
	length = strlen(lpsz);
Packit Service fa4841
Packit Service fa4841
	if (length < 1)
Packit Service b1ea74
		return (LPSTR)NULL;
Packit Service fa4841
Packit Service fa4841
	if (length == 1)
Packit Service fa4841
	{
Packit Service fa4841
		char c = *lpsz;
Packit Service fa4841
Packit Service fa4841
		if ((c >= 'A') && (c <= 'Z'))
Packit Service fa4841
			c = c + 32;
Packit Service fa4841
Packit Service fa4841
		*lpsz = c;
Packit Service fa4841
		return lpsz;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < length; i++)
Packit Service fa4841
	{
Packit Service fa4841
		if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
Packit Service fa4841
			lpsz[i] = lpsz[i] + 32;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return lpsz;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LPWSTR CharLowerW(LPWSTR lpsz)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "CharLowerW unimplemented!");
Packit Service b1ea74
	return (LPWSTR)NULL;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
Packit Service fa4841
{
Packit Service fa4841
	DWORD i;
Packit Service fa4841
Packit Service fa4841
	if (cchLength < 1)
Packit Service fa4841
		return 0;
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < cchLength; i++)
Packit Service fa4841
	{
Packit Service fa4841
		if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
Packit Service fa4841
			lpsz[i] = lpsz[i] + 32;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return cchLength;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength)
Packit Service fa4841
{
Packit Service fa4841
	DWORD i;
Packit Service fa4841
	WCHAR value;
Packit Service fa4841
Packit Service fa4841
	for (i = 0; i < cchLength; i++)
Packit Service fa4841
	{
Packit Service fa4841
		Data_Read_UINT16(&lpsz[i], value);
Packit Service fa4841
		value = WINPR_TOLOWERW(value);
Packit Service fa4841
		Data_Write_UINT16(&lpsz[i], value);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return cchLength;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharAlphaA(CHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')))
Packit Service fa4841
		return 1;
Packit Service fa4841
	else
Packit Service fa4841
		return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharAlphaW(WCHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "IsCharAlphaW unimplemented!");
Packit Service fa4841
	return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharAlphaNumericA(CHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) ||
Packit Service b1ea74
	    ((ch >= '0') && (ch <= '9')))
Packit Service fa4841
		return 1;
Packit Service fa4841
	else
Packit Service fa4841
		return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharAlphaNumericW(WCHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "IsCharAlphaNumericW unimplemented!");
Packit Service fa4841
	return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharUpperA(CHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	if ((ch >= 'A') && (ch <= 'Z'))
Packit Service fa4841
		return 1;
Packit Service fa4841
	else
Packit Service fa4841
		return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharUpperW(WCHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "IsCharUpperW unimplemented!");
Packit Service fa4841
	return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharLowerA(CHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	if ((ch >= 'a') && (ch <= 'z'))
Packit Service fa4841
		return 1;
Packit Service fa4841
	else
Packit Service fa4841
		return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsCharLowerW(WCHAR ch)
Packit Service fa4841
{
Packit Service fa4841
	WLog_ERR(TAG, "IsCharLowerW unimplemented!");
Packit Service fa4841
	return 0;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int lstrlenA(LPCSTR lpString)
Packit Service fa4841
{
Packit Service b1ea74
	return (int)strlen(lpString);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int lstrlenW(LPCWSTR lpString)
Packit Service fa4841
{
Packit Service fa4841
	LPWSTR p;
Packit Service fa4841
Packit Service fa4841
	if (!lpString)
Packit Service fa4841
		return 0;
Packit Service fa4841
Packit Service b1ea74
	p = (LPWSTR)lpString;
Packit Service fa4841
Packit Service fa4841
	while (*p)
Packit Service fa4841
		p++;
Packit Service fa4841
Packit Service b1ea74
	return (int)(p - lpString);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Packit Service fa4841
{
Packit Service fa4841
	return strcmp(lpString1, lpString2);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Packit Service fa4841
{
Packit Service fa4841
	WCHAR value1, value2;
Packit Service fa4841
Packit Service fa4841
	while (*lpString1 && (*lpString1 == *lpString2))
Packit Service fa4841
	{
Packit Service fa4841
		lpString1++;
Packit Service fa4841
		lpString2++;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	Data_Read_UINT16(lpString1, value1);
Packit Service fa4841
	Data_Read_UINT16(lpString2, value2);
Packit Service fa4841
	return value1 - value2;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
int ConvertLineEndingToLF(char* str, int size)
Packit Service fa4841
{
Packit Service fa4841
	int status;
Packit Service fa4841
	char* end;
Packit Service fa4841
	char* pInput;
Packit Service fa4841
	char* pOutput;
Packit Service fa4841
	end = &str[size];
Packit Service fa4841
	pInput = pOutput = str;
Packit Service fa4841
Packit Service fa4841
	while (pInput < end)
Packit Service fa4841
	{
Packit Service fa4841
		if ((pInput[0] == '\r') && (pInput[1] == '\n'))
Packit Service fa4841
		{
Packit Service fa4841
			*pOutput++ = '\n';
Packit Service fa4841
			pInput += 2;
Packit Service fa4841
		}
Packit Service fa4841
		else
Packit Service fa4841
		{
Packit Service fa4841
			*pOutput++ = *pInput++;
Packit Service fa4841
		}
Packit Service fa4841
	}
Packit Service fa4841
Packit Service b1ea74
	status = (int)(pOutput - str);
Packit Service fa4841
	return status;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
char* ConvertLineEndingToCRLF(const char* str, int* size)
Packit Service fa4841
{
Packit Service fa4841
	int count;
Packit Service fa4841
	char* newStr;
Packit Service fa4841
	char* pOutput;
Packit Service fa4841
	const char* end;
Packit Service fa4841
	const char* pInput;
Packit Service fa4841
	end = &str[*size];
Packit Service fa4841
	count = 0;
Packit Service fa4841
	pInput = str;
Packit Service fa4841
Packit Service fa4841
	while (pInput < end)
Packit Service fa4841
	{
Packit Service fa4841
		if (*pInput == '\n')
Packit Service fa4841
			count++;
Packit Service fa4841
Packit Service fa4841
		pInput++;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service b1ea74
	newStr = (char*)malloc(*size + (count * 2) + 1);
Packit Service fa4841
Packit Service fa4841
	if (!newStr)
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service fa4841
	pInput = str;
Packit Service fa4841
	pOutput = newStr;
Packit Service fa4841
Packit Service fa4841
	while (pInput < end)
Packit Service fa4841
	{
Packit Service fa4841
		if ((*pInput == '\n') && ((pInput > str) && (pInput[-1] != '\r')))
Packit Service fa4841
		{
Packit Service fa4841
			*pOutput++ = '\r';
Packit Service fa4841
			*pOutput++ = '\n';
Packit Service fa4841
		}
Packit Service fa4841
		else
Packit Service fa4841
		{
Packit Service fa4841
			*pOutput++ = *pInput;
Packit Service fa4841
		}
Packit Service fa4841
Packit Service fa4841
		pInput++;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service b1ea74
	*size = (int)(pOutput - newStr);
Packit Service fa4841
	return newStr;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
char* StrSep(char** stringp, const char* delim)
Packit Service fa4841
{
Packit Service fa4841
	char* start = *stringp;
Packit Service fa4841
	char* p;
Packit Service fa4841
	p = (start != NULL) ? strpbrk(start, delim) : NULL;
Packit Service fa4841
Packit Service fa4841
	if (!p)
Packit Service fa4841
		*stringp = NULL;
Packit Service fa4841
	else
Packit Service fa4841
	{
Packit Service fa4841
		*p = '\0';
Packit Service fa4841
		*stringp = p + 1;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return start;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
Packit Service fa4841
{
Packit Service fa4841
#if defined(_WIN32)
Packit Service fa4841
	char c;
Packit Service b1ea74
	char* n;
Packit Service fa4841
	size_t step = 32;
Packit Service fa4841
	size_t used = 0;
Packit Service fa4841
Packit Service fa4841
	if (!lineptr || !size)
Packit Service fa4841
	{
Packit Service fa4841
		errno = EINVAL;
Packit Service fa4841
		return -1;
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	do
Packit Service fa4841
	{
Packit Service fa4841
		if (used + 2 >= *size)
Packit Service fa4841
		{
Packit Service fa4841
			*size += step;
Packit Service fa4841
			n = realloc(*lineptr, *size);
Packit Service b1ea74
Packit Service fa4841
			if (!n)
Packit Service fa4841
			{
Packit Service fa4841
				return -1;
Packit Service fa4841
			}
Packit Service b1ea74
Packit Service fa4841
			*lineptr = n;
Packit Service fa4841
		}
Packit Service fa4841
Packit Service b1ea74
		c = fgetc(stream);
Packit Service b1ea74
Packit Service b1ea74
		if (c != EOF)
Packit Service b1ea74
			(*lineptr)[used++] = c;
Packit Service b1ea74
	} while ((c != '\n') && (c != '\r') && (c != EOF));
Packit Service b1ea74
Packit Service b1ea74
	(*lineptr)[used] = '\0';
Packit Service fa4841
	return used;
Packit Service fa4841
#elif !defined(ANDROID) && !defined(IOS)
Packit Service fa4841
	return getline(lineptr, size, stream);
Packit Service fa4841
#else
Packit Service fa4841
	return -1;
Packit Service fa4841
#endif
Packit Service fa4841
}