mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 08:24:16 +09:00
Added strndup replacement
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <winpr/config.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
@@ -211,6 +212,10 @@ extern "C"
|
||||
|
||||
WINPR_API INT64 GetLine(char** lineptr, size_t* size, FILE* stream);
|
||||
|
||||
#if !defined(HAVE_STRNDUP)
|
||||
WINPR_API char* strndup(const char* s, size_t n);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <winpr/config.h>
|
||||
#include <winpr/assert.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@@ -643,3 +644,25 @@ INT64 GetLine(char** lineptr, size_t* size, FILE* stream)
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(HAVE_STRNDUP)
|
||||
char* strndup(const char* s, size_t n)
|
||||
{
|
||||
char* rc;
|
||||
size_t len;
|
||||
|
||||
WINPR_ASSERT(s || (n == 0));
|
||||
if (n == 0)
|
||||
return NULL;
|
||||
|
||||
len = strnlen(s, n);
|
||||
if (len == n)
|
||||
len++;
|
||||
|
||||
rc = calloc(len, sizeof(char));
|
||||
if (!rc)
|
||||
return NULL;
|
||||
memcpy(rc, s, n);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user