*/
char *stat_mem_strdup(const char *src, bool empty) {
size_t len = 0;
- char *ptr = NULL;
+ char *ptr = nullptr;
if (!src)
- return NULL;
+ return nullptr;
len = strlen(src);
if ((!empty ? len : true) && (ptr = (char*)mem_a(len + 1))) {
* The reallocate function for resizing vectors.
*/
void _util_vec_grow(void **a, size_t i, size_t s) {
- vector_t *d = vec_meta(*a);
+ vector_t *d = nullptr;
size_t m = 0;
- void *p = NULL;
+ void *p = nullptr;
if (*a) {
+ d = vec_meta(*a);
m = 2 * d->allocated + i;
p = mem_r(d, s * m + sizeof(vector_t));
} else {
* all around. This is the internal interface, please look for
* EXPOSED INTERFACE comment below
*/
-typedef struct hash_node_t {
- char *key; /* the key for this node in table */
- void *value; /* pointer to the data as void* */
- struct hash_node_t *next; /* next node (linked list) */
-} hash_node_t;
+struct hash_node_t {
+ char *key; /* the key for this node in table */
+ void *value; /* pointer to the data as void* */
+ hash_node_t *next; /* next node (linked list) */
+};
size_t hash(const char *key);
static hash_node_t *_util_htnewpair(const char *key, void *value) {
hash_node_t *node;
if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t))))
- return NULL;
+ return nullptr;
if (!(node->key = util_strdupe(key))) {
mem_d(node);
- return NULL;
+ return nullptr;
}
node->value = value;
- node->next = NULL;
+ node->next = nullptr;
return node;
}
* util_htdel(table) -- to delete the table
*/
hash_table_t *util_htnew(size_t size) {
- hash_table_t *hashtable = NULL;
+ hash_table_t *hashtable = nullptr;
if (size < 1)
- return NULL;
+ return nullptr;
if (!(hashtable = (hash_table_t*)mem_a(sizeof(hash_table_t))))
- return NULL;
+ return nullptr;
if (!(hashtable->table = (hash_node_t**)mem_a(sizeof(hash_node_t*) * size))) {
mem_d(hashtable);
- return NULL;
+ return nullptr;
}
hashtable->size = size;
}
void util_htseth(hash_table_t *ht, const char *key, size_t bin, void *value) {
- hash_node_t *newnode = NULL;
- hash_node_t *next = NULL;
- hash_node_t *last = NULL;
+ hash_node_t *newnode = nullptr;
+ hash_node_t *next = nullptr;
+ hash_node_t *last = nullptr;
next = ht->table[bin];
pair = pair->next;
if (!pair || !pair->key || strcmp(key, pair->key) != 0)
- return NULL;
+ return nullptr;
return pair->value;
}
if (cmp == 0)
return pair->value;
if (cmp < 0)
- return NULL;
+ return nullptr;
pair = pair->next;
continue;
}
}
pair = pair->next;
}
- return NULL;
+ return nullptr;
}
/*
}
void util_htdel(hash_table_t *ht) {
- util_htrem(ht, NULL);
+ util_htrem(ht, nullptr);
}