mirror of
https://github.com/DaveGamble/cJSON
synced 2025-05-09 19:47:57 +00:00
cJSON_Utils: own strdup for C89 compatibility
This commit is contained in:
parent
a148520ffb
commit
1dff6f160f
@ -4,6 +4,21 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "cJSON_Utils.h"
|
#include "cJSON_Utils.h"
|
||||||
|
|
||||||
|
static char* cJSONUtils_strdup(const char* str)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char* copy;
|
||||||
|
|
||||||
|
len = strlen(str) + 1;
|
||||||
|
if (!(copy = (char*)malloc(len)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(copy, str, len);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
static int cJSONUtils_strcasecmp(const char *s1, const char *s2)
|
static int cJSONUtils_strcasecmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
if (!s1)
|
if (!s1)
|
||||||
@ -107,7 +122,7 @@ char *cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *target)
|
|||||||
if (object == target)
|
if (object == target)
|
||||||
{
|
{
|
||||||
/* found */
|
/* found */
|
||||||
return strdup("");
|
return cJSONUtils_strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* recursively search all children of the object */
|
/* recursively search all children of the object */
|
||||||
@ -213,7 +228,7 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
|
|||||||
cJSON *ret = 0;
|
cJSON *ret = 0;
|
||||||
|
|
||||||
/* copy path and split it in parent and child */
|
/* copy path and split it in parent and child */
|
||||||
parentptr = strdup(path);
|
parentptr = cJSONUtils_strdup(path);
|
||||||
childptr = strrchr(parentptr, '/'); /* last '/' */
|
childptr = strrchr(parentptr, '/'); /* last '/' */
|
||||||
if (childptr)
|
if (childptr)
|
||||||
{
|
{
|
||||||
@ -416,7 +431,7 @@ static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch)
|
|||||||
/* Now, just add "value" to "path". */
|
/* Now, just add "value" to "path". */
|
||||||
|
|
||||||
/* split pointer in parent and child */
|
/* split pointer in parent and child */
|
||||||
parentptr = strdup(path->valuestring);
|
parentptr = cJSONUtils_strdup(path->valuestring);
|
||||||
childptr = strrchr(parentptr, '/');
|
childptr = strrchr(parentptr, '/');
|
||||||
if (childptr)
|
if (childptr)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user