2012-05-06 06:09:08 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* String Manipulation (CRT)
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 06:04:14 +04:00
|
|
|
#include <errno.h>
|
2015-12-18 11:45:44 +03:00
|
|
|
#include <stdio.h>
|
2012-05-22 06:04:14 +04:00
|
|
|
#include <wctype.h>
|
|
|
|
|
2012-05-06 06:09:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2016-04-27 14:35:09 +03:00
|
|
|
#include <winpr/endian.h>
|
2012-05-06 06:09:08 +04:00
|
|
|
|
|
|
|
/* String Manipulation (CRT): http://msdn.microsoft.com/en-us/library/f0151s4x.aspx */
|
|
|
|
|
2014-08-18 19:22:22 +04:00
|
|
|
#include "../log.h"
|
2014-08-18 20:57:08 +04:00
|
|
|
#define TAG WINPR_TAG("crt")
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
char* _strdup(const char* strSource)
|
2012-05-06 06:09:08 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
char* strDestination;
|
2012-05-06 06:09:08 +04:00
|
|
|
|
|
|
|
if (strSource == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
strDestination = strdup(strSource);
|
|
|
|
|
|
|
|
if (strDestination == NULL)
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG,"strdup");
|
2012-05-06 06:09:08 +04:00
|
|
|
|
|
|
|
return strDestination;
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* _wcsdup(const WCHAR* strSource)
|
2012-05-06 06:09:08 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* strDestination;
|
2012-05-06 06:09:08 +04:00
|
|
|
|
|
|
|
if (strSource == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2015-02-02 19:48:54 +03:00
|
|
|
#if defined(__APPLE__) && defined(__MACH__) || defined(ANDROID) || defined(sun)
|
2014-08-18 21:34:47 +04:00
|
|
|
strDestination = malloc(wcslen((wchar_t*)strSource));
|
2012-05-25 06:20:51 +04:00
|
|
|
|
|
|
|
if (strDestination != NULL)
|
2014-08-18 21:34:47 +04:00
|
|
|
wcscpy((wchar_t*)strDestination, (const wchar_t*)strSource);
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2012-05-06 06:09:08 +04:00
|
|
|
#else
|
2014-08-18 21:34:47 +04:00
|
|
|
strDestination = (WCHAR*) wcsdup((wchar_t*) strSource);
|
2012-05-06 06:09:08 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strDestination == NULL)
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG,"wcsdup");
|
2012-05-06 06:09:08 +04:00
|
|
|
|
|
|
|
return strDestination;
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
int _stricmp(const char* string1, const char* string2)
|
2012-07-28 23:49:16 +04:00
|
|
|
{
|
|
|
|
return strcasecmp(string1, string2);
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
int _strnicmp(const char* string1, const char* string2, size_t count)
|
2012-11-03 23:13:13 +04:00
|
|
|
{
|
|
|
|
return strncasecmp(string1, string2, count);
|
|
|
|
}
|
|
|
|
|
2012-10-29 06:16:21 +04:00
|
|
|
/* _wcscmp -> wcscmp */
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
int _wcscmp(const WCHAR* string1, const WCHAR* string2)
|
2012-10-29 06:16:21 +04:00
|
|
|
{
|
|
|
|
while (*string1 && (*string1 == *string2))
|
|
|
|
{
|
|
|
|
string1++;
|
|
|
|
string2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *string1 - *string2;
|
|
|
|
}
|
|
|
|
|
2012-10-28 04:25:11 +04:00
|
|
|
/* _wcslen -> wcslen */
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
size_t _wcslen(const WCHAR* str)
|
2012-10-28 04:25:11 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* p = (WCHAR*) str;
|
2012-10-28 04:25:11 +04:00
|
|
|
|
2013-03-16 00:47:24 +04:00
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-28 04:25:11 +04:00
|
|
|
while (*p)
|
|
|
|
p++;
|
|
|
|
|
|
|
|
return (p - str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _wcschr -> wcschr */
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* _wcschr(const WCHAR* str, WCHAR c)
|
2012-10-28 04:25:11 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* p = (WCHAR*) str;
|
2012-10-28 04:25:11 +04:00
|
|
|
|
|
|
|
while (*p && (*p != c))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
return ((*p == c) ? p : NULL);
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
char* strtok_s(char* strToken, const char* strDelimit, char** context)
|
2012-07-30 23:21:57 +04:00
|
|
|
{
|
|
|
|
return strtok_r(strToken, strDelimit, context);
|
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context)
|
2012-10-28 04:25:11 +04:00
|
|
|
{
|
2014-08-18 21:34:47 +04:00
|
|
|
WCHAR* nextToken;
|
2012-10-28 04:25:11 +04:00
|
|
|
|
|
|
|
if (!strToken)
|
|
|
|
strToken = *context;
|
|
|
|
|
|
|
|
while (*strToken && _wcschr(strDelimit, *strToken))
|
|
|
|
strToken++;
|
|
|
|
|
|
|
|
if (!*strToken)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nextToken = strToken++;
|
|
|
|
|
|
|
|
while (*strToken && !(_wcschr(strDelimit, *strToken)))
|
|
|
|
strToken++;
|
|
|
|
|
|
|
|
if (*strToken)
|
|
|
|
*strToken++ = 0;
|
|
|
|
|
|
|
|
*context = strToken;
|
|
|
|
return nextToken;
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_WIN32) || defined(_UWP)
|
|
|
|
|
2012-05-22 06:04:14 +04:00
|
|
|
/* Windows API Sets - api-ms-win-core-string-l2-1-0.dll
|
|
|
|
* http://msdn.microsoft.com/en-us/library/hh802935/
|
|
|
|
*/
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
#include "casing.c"
|
|
|
|
|
2012-05-22 06:04:14 +04:00
|
|
|
LPSTR CharUpperA(LPSTR lpsz)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int length;
|
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
if (!lpsz)
|
|
|
|
return NULL;
|
2012-05-22 06:04:14 +04:00
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
length = (int) strlen(lpsz);
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2012-05-22 06:04:14 +04:00
|
|
|
if (length < 1)
|
|
|
|
return (LPSTR) NULL;
|
|
|
|
|
|
|
|
if (length == 1)
|
|
|
|
{
|
|
|
|
char c = *lpsz;
|
|
|
|
|
|
|
|
if ((c >= 'a') && (c <= 'z'))
|
|
|
|
c = c - 32;
|
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
*lpsz = c;
|
|
|
|
return lpsz;
|
2012-05-22 06:04:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
|
|
|
|
lpsz[i] = lpsz[i] - 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lpsz;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPWSTR CharUpperW(LPWSTR lpsz)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "CharUpperW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return (LPWSTR) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
|
|
|
|
{
|
2016-02-06 00:28:45 +03:00
|
|
|
DWORD i;
|
2012-05-22 06:04:14 +04:00
|
|
|
|
|
|
|
if (cchLength < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < cchLength; i++)
|
|
|
|
{
|
|
|
|
if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
|
|
|
|
lpsz[i] = lpsz[i] - 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cchLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength)
|
|
|
|
{
|
|
|
|
DWORD i;
|
2016-04-27 14:35:09 +03:00
|
|
|
WCHAR value;
|
2012-05-22 06:04:14 +04:00
|
|
|
|
|
|
|
for (i = 0; i < cchLength; i++)
|
|
|
|
{
|
2016-04-27 14:35:09 +03:00
|
|
|
Data_Read_UINT16(&lpsz[i], value);
|
|
|
|
value = WINPR_TOUPPERW(value);
|
|
|
|
Data_Write_UINT16(&lpsz[i], value);
|
2012-05-22 06:04:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cchLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPSTR CharLowerA(LPSTR lpsz)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int length;
|
|
|
|
|
2013-08-29 12:55:07 +04:00
|
|
|
if (!lpsz)
|
|
|
|
return (LPSTR) NULL;
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
length = (int) strlen(lpsz);
|
2012-05-22 06:04:14 +04:00
|
|
|
|
|
|
|
if (length < 1)
|
|
|
|
return (LPSTR) NULL;
|
|
|
|
|
|
|
|
if (length == 1)
|
|
|
|
{
|
|
|
|
char c = *lpsz;
|
|
|
|
|
|
|
|
if ((c >= 'A') && (c <= 'Z'))
|
|
|
|
c = c + 32;
|
|
|
|
|
2013-08-29 12:55:07 +04:00
|
|
|
*lpsz = c;
|
|
|
|
return lpsz;
|
2012-05-22 06:04:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
|
|
|
|
lpsz[i] = lpsz[i] + 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lpsz;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPWSTR CharLowerW(LPWSTR lpsz)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "CharLowerW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return (LPWSTR) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
|
|
|
|
{
|
2016-02-06 00:28:45 +03:00
|
|
|
DWORD i;
|
2012-05-22 06:04:14 +04:00
|
|
|
|
|
|
|
if (cchLength < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < cchLength; i++)
|
|
|
|
{
|
|
|
|
if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
|
|
|
|
lpsz[i] = lpsz[i] + 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cchLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength)
|
|
|
|
{
|
|
|
|
DWORD i;
|
2016-04-27 14:35:09 +03:00
|
|
|
WCHAR value;
|
2012-05-22 06:04:14 +04:00
|
|
|
|
|
|
|
for (i = 0; i < cchLength; i++)
|
|
|
|
{
|
2016-04-27 14:35:09 +03:00
|
|
|
Data_Read_UINT16(&lpsz[i], value);
|
|
|
|
value = WINPR_TOLOWERW(value);
|
|
|
|
Data_Write_UINT16(&lpsz[i], value);
|
2012-05-22 06:04:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cchLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharAlphaA(CHAR ch)
|
|
|
|
{
|
|
|
|
if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharAlphaW(WCHAR ch)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "IsCharAlphaW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharAlphaNumericA(CHAR ch)
|
|
|
|
{
|
|
|
|
if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) ||
|
|
|
|
((ch >= '0') && (ch <= '9')))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharAlphaNumericW(WCHAR ch)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "IsCharAlphaNumericW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharUpperA(CHAR ch)
|
|
|
|
{
|
|
|
|
if ((ch >= 'A') && (ch <= 'Z'))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharUpperW(WCHAR ch)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "IsCharUpperW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharLowerA(CHAR ch)
|
|
|
|
{
|
|
|
|
if ((ch >= 'a') && (ch <= 'z'))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL IsCharLowerW(WCHAR ch)
|
|
|
|
{
|
2014-08-18 20:57:08 +04:00
|
|
|
WLog_ERR(TAG, "IsCharLowerW unimplemented!");
|
2012-05-22 06:04:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-04 00:30:15 +04:00
|
|
|
int lstrlenA(LPCSTR lpString)
|
|
|
|
{
|
2016-02-06 00:28:45 +03:00
|
|
|
return (int) strlen(lpString);
|
2012-06-04 00:30:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int lstrlenW(LPCWSTR lpString)
|
|
|
|
{
|
|
|
|
LPWSTR p;
|
|
|
|
|
|
|
|
if (!lpString)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = (LPWSTR) lpString;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
p++;
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
return (int) (p - lpString);
|
2012-06-04 00:30:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
|
|
|
|
{
|
|
|
|
return strcmp(lpString1, lpString2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
|
|
|
|
{
|
|
|
|
while (*lpString1 && (*lpString1 == *lpString2))
|
|
|
|
{
|
|
|
|
lpString1++;
|
|
|
|
lpString2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *lpString1 - *lpString2;
|
|
|
|
}
|
|
|
|
|
2012-05-06 06:09:08 +04:00
|
|
|
#endif
|
2014-10-17 02:07:44 +04:00
|
|
|
|
|
|
|
int ConvertLineEndingToLF(char* str, int size)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
char* end;
|
|
|
|
char* pInput;
|
|
|
|
char* pOutput;
|
|
|
|
|
|
|
|
end = &str[size];
|
|
|
|
pInput = pOutput = str;
|
|
|
|
|
|
|
|
while (pInput < end)
|
|
|
|
{
|
|
|
|
if ((pInput[0] == '\r') && (pInput[1] == '\n'))
|
|
|
|
{
|
|
|
|
*pOutput++ = '\n';
|
|
|
|
pInput += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pOutput++ = *pInput++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
status = (int) (pOutput - str);
|
2014-10-17 02:07:44 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* ConvertLineEndingToCRLF(const char* str, int* size)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
char* newStr;
|
|
|
|
char* pOutput;
|
|
|
|
const char* end;
|
|
|
|
const char* pInput;
|
|
|
|
|
|
|
|
end = &str[*size];
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
pInput = str;
|
|
|
|
|
|
|
|
while (pInput < end)
|
|
|
|
{
|
|
|
|
if (*pInput == '\n')
|
|
|
|
count++;
|
|
|
|
|
|
|
|
pInput++;
|
|
|
|
}
|
|
|
|
|
|
|
|
newStr = (char*) malloc(*size + (count * 2) + 1);
|
|
|
|
|
|
|
|
if (!newStr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pInput = str;
|
|
|
|
pOutput = newStr;
|
|
|
|
|
|
|
|
while (pInput < end)
|
|
|
|
{
|
|
|
|
if ((*pInput == '\n') && ((pInput > str) && (pInput[-1] != '\r')))
|
|
|
|
{
|
|
|
|
*pOutput++ = '\r';
|
|
|
|
*pOutput++ = '\n';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pOutput++ = *pInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
pInput++;
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
*size = (int) (pOutput - newStr);
|
2014-10-17 02:07:44 +04:00
|
|
|
|
|
|
|
return newStr;
|
|
|
|
}
|
|
|
|
|
2015-06-09 16:32:50 +03:00
|
|
|
char* StrSep(char** stringp, const char* delim)
|
|
|
|
{
|
|
|
|
char* start = *stringp;
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
p = (start != NULL) ? strpbrk(start, delim) : NULL;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
*stringp = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
*stringp = p + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2015-12-18 11:45:44 +03:00
|
|
|
INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
|
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
|
|
|
char c;
|
|
|
|
char *n;
|
|
|
|
size_t step = 32;
|
|
|
|
size_t used = 0;
|
2015-06-09 16:32:50 +03:00
|
|
|
|
2015-12-18 11:45:44 +03:00
|
|
|
if (!lineptr || !size)
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2015-06-09 16:32:50 +03:00
|
|
|
|
2015-12-18 11:45:44 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (used + 2 >= *size)
|
|
|
|
{
|
|
|
|
*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';
|
|
|
|
|
|
|
|
return used;
|
2015-12-18 12:36:28 +03:00
|
|
|
#elif !defined(ANDROID) && !defined(IOS)
|
2015-12-18 11:45:44 +03:00
|
|
|
return getline(lineptr, size, stream);
|
2015-12-18 12:36:28 +03:00
|
|
|
#else
|
|
|
|
return -1;
|
2015-12-18 11:45:44 +03:00
|
|
|
#endif
|
|
|
|
}
|