Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/compat/jansson/memory.c
1201 views
1
/*
2
* Copyright (c) 2009-2013 Petri Lehtinen <[email protected]>
3
* Copyright (c) 2011-2012 Basile Starynkevitch <[email protected]>
4
*
5
* Jansson is free software; you can redistribute it and/or modify it
6
* under the terms of the MIT license. See LICENSE for details.
7
*/
8
9
#include <stdlib.h>
10
#include <string.h>
11
12
#include "jansson.h"
13
#include "jansson_private.h"
14
15
/* memory function pointers */
16
static json_malloc_t do_malloc = malloc;
17
static json_free_t do_free = free;
18
19
void *jsonp_malloc(size_t size)
20
{
21
if(!size)
22
return NULL;
23
24
return (*do_malloc)(size);
25
}
26
27
void jsonp_free(void *ptr)
28
{
29
if(!ptr)
30
return;
31
32
(*do_free)(ptr);
33
}
34
35
char *jsonp_strdup(const char *str)
36
{
37
char *new_str;
38
size_t len;
39
40
len = strlen(str);
41
if(len == (size_t)-1)
42
return NULL;
43
44
new_str = jsonp_malloc(len + 1);
45
if(!new_str)
46
return NULL;
47
48
memcpy(new_str, str, len + 1);
49
return new_str;
50
}
51
52
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn)
53
{
54
do_malloc = malloc_fn;
55
do_free = free_fn;
56
}
57
58