[rcore] Add StringDuplicate
This commit is contained in:
parent
935f3da3ff
commit
8b27166194
3 changed files with 32 additions and 0 deletions
|
|
@ -123,6 +123,10 @@
|
|||
// - SUPPORT_FILEFORMAT_JPG
|
||||
#define SUPPORT_CLIPBOARD_IMAGE 1
|
||||
#endif
|
||||
#ifndef SUPPORT_POSIX_STRDUP
|
||||
// Use posix strdup or built-in one
|
||||
#define SUPPORT_POSIX_STRDUP 1
|
||||
#endif
|
||||
|
||||
// rcore: Configuration values
|
||||
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be
|
||||
|
|
|
|||
|
|
@ -1113,6 +1113,7 @@ RLAPI void UnloadRandomSequence(int *sequence); // Unload random values
|
|||
RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (filename extension defines format)
|
||||
RLAPI void SetConfigFlags(unsigned int flags); // Set up init configuration flags (view FLAGS)
|
||||
RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available)
|
||||
RLAPI char *StringDuplicate(const char *string); // Duplicates string into a new copy (platform agnostic strdup)
|
||||
|
||||
// Logging system
|
||||
RLAPI void SetTraceLogLevel(int logLevel); // Set the current threshold (minimum) log level
|
||||
|
|
|
|||
27
src/rcore.c
27
src/rcore.c
|
|
@ -1853,6 +1853,33 @@ void SetConfigFlags(unsigned int flags)
|
|||
FLAG_SET(CORE.Window.flags, flags);
|
||||
}
|
||||
|
||||
// Duplicates string into a new one (platform agnostic strdup)
|
||||
char *StringDuplicate(const char *string)
|
||||
{
|
||||
#if SUPPORT_POSIX_STRDUP
|
||||
#if defined(_WIN32) || defined(_MSC_VER)
|
||||
return _strdup(string);
|
||||
#else
|
||||
return strdup(string);
|
||||
#endif
|
||||
#else
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
// NOTE: the final string (newString) should be stringLength + 1 (e.g. strlen("hello") + 1 = 6).
|
||||
// one extra char is required for the null-terminator ('\0').
|
||||
|
||||
size_t stringLength = strlen(string);
|
||||
|
||||
char *newString = RL_CALLOC(stringLength + 1, sizeof(char));
|
||||
strncpy(newString, string, stringLength);
|
||||
|
||||
newString[stringLength + 1] = '\0';
|
||||
|
||||
return newString;
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Logging system
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue