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:
25
jv_alloc.c
25
jv_alloc.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user