1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Add jv_mem_strdup*() and callocs too

This commit is contained in:
Nicolas Williams
2015-05-25 21:12:29 -05:00
parent 8af52aaf52
commit dff96aebcf
2 changed files with 29 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "jv_alloc.h"
struct nomem_handler {
@@ -129,6 +130,30 @@ void* jv_mem_alloc_unguarded(size_t sz) {
return malloc(sz);
}
void* jv_mem_calloc(size_t nemb, size_t sz) {
void* p = calloc(nemb, sz);
if (!p) {
memory_exhausted();
}
return p;
}
void* jv_mem_calloc_unguarded(size_t nemb, size_t sz) {
return calloc(nemb, sz);
}
char* jv_mem_strdup(const char *s) {
char *p = strdup(s);
if (!p) {
memory_exhausted();
}
return p;
}
char* jv_mem_strdup_unguarded(const char *s) {
return strdup(s);
}
void jv_mem_free(void* p) {
free(p);
}