Replaced getline with custom GetLine.

This commit is contained in:
Armin Novak 2015-12-18 09:45:44 +01:00 committed by Armin Novak
parent b35f6658b9
commit 5e46a6e4be
3 changed files with 43 additions and 4 deletions

View File

@ -340,9 +340,9 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char**
{
size_t username_size = 0;
printf("%s", prompt[0]);
if (getline(username, &username_size, stdin) < 0)
if (GetLine(username, &username_size, stdin) < 0)
{
WLog_ERR(TAG, "getline returned %s [%d]", strerror(errno), errno);
WLog_ERR(TAG, "GetLine returned %s [%d]", strerror(errno), errno);
goto fail;
}
@ -357,9 +357,9 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char**
{
size_t domain_size = 0;
printf("%s", prompt[1]);
if (getline(domain, &domain_size, stdin) < 0)
if (GetLine(domain, &domain_size, stdin) < 0)
{
WLog_ERR(TAG, "getline returned %s [%d]", strerror(errno), errno);
WLog_ERR(TAG, "GetLine returned %s [%d]", strerror(errno), errno);
goto fail;
}

View File

@ -189,6 +189,8 @@ WINPR_API char* ConvertLineEndingToCRLF(const char* str, int* size);
WINPR_API char* StrSep(char** stringp, const char* delim);
WINPR_API INT64 GetLine(char** lineptr, size_t* size, FILE* stream);
#ifdef __cplusplus
}
#endif

View File

@ -22,6 +22,7 @@
#endif
#include <errno.h>
#include <stdio.h>
#include <wctype.h>
#include <winpr/crt.h>
@ -481,4 +482,40 @@ char* StrSep(char** stringp, const char* delim)
return start;
}
INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
{
#if defined(_WIN32)
char c;
char *n;
size_t step = 32;
size_t used = 0;
if (!lineptr || !size)
{
errno = EINVAL;
return -1;
}
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;
#else
return getline(lineptr, size, stream);
#endif
}