mirror of https://github.com/GOSTSec/sgminer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.0 KiB
57 lines
1.0 KiB
14 years ago
|
/*
|
||
11 years ago
|
* Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org>
|
||
11 years ago
|
* Copyright (c) 2011-2012 Basile Starynkevitch <basile@starynkevitch.net>
|
||
14 years ago
|
*
|
||
|
* Jansson is free software; you can redistribute it and/or modify it
|
||
|
* under the terms of the MIT license. See LICENSE for details.
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
11 years ago
|
#include "jansson.h"
|
||
14 years ago
|
#include "jansson_private.h"
|
||
|
|
||
|
/* memory function pointers */
|
||
|
static json_malloc_t do_malloc = malloc;
|
||
|
static json_free_t do_free = free;
|
||
|
|
||
|
void *jsonp_malloc(size_t size)
|
||
|
{
|
||
|
if(!size)
|
||
|
return NULL;
|
||
|
|
||
|
return (*do_malloc)(size);
|
||
|
}
|
||
|
|
||
|
void jsonp_free(void *ptr)
|
||
|
{
|
||
|
if(!ptr)
|
||
|
return;
|
||
|
|
||
|
(*do_free)(ptr);
|
||
|
}
|
||
|
|
||
|
char *jsonp_strdup(const char *str)
|
||
|
{
|
||
|
char *new_str;
|
||
11 years ago
|
size_t len;
|
||
14 years ago
|
|
||
11 years ago
|
len = strlen(str);
|
||
|
if(len == (size_t)-1)
|
||
|
return NULL;
|
||
|
|
||
|
new_str = jsonp_malloc(len + 1);
|
||
14 years ago
|
if(!new_str)
|
||
|
return NULL;
|
||
|
|
||
11 years ago
|
memcpy(new_str, str, len + 1);
|
||
14 years ago
|
return new_str;
|
||
|
}
|
||
|
|
||
|
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn)
|
||
|
{
|
||
|
do_malloc = malloc_fn;
|
||
|
do_free = free_fn;
|
||
|
}
|