myMPD
Internal API documentation
Loading...
Searching...
No Matches
mem.h
1/*
2 SPDX-License-Identifier: GPL-3.0-or-later
3 myMPD (c) 2018-2026 Juergen Mang <mail@jcgames.de>
4 https://github.com/jcorporation/mympd
5*/
6
7#ifndef MYMPD_MEM_H
8#define MYMPD_MEM_H
9
10#include "src/lib/log.h"
11
12#include <stdlib.h>
13
14char *my_strdup(const char *str, size_t len);
15
21__attribute__((malloc))
22static inline void *malloc_assert(size_t size) {
23 void *p = malloc(size);
24 if (p == NULL) {
25 MYMPD_LOG_EMERG(NULL, "Failure allocating %lu bytes of memory", (unsigned long) size);
26 abort();
27 }
28 return p;
29}
30
37__attribute__((malloc))
38static inline void *realloc_assert(void *ptr, size_t size) {
39 void *p = realloc(ptr, size);
40 if (p == NULL) {
41 MYMPD_LOG_EMERG(NULL, "Failure allocating %lu bytes of memory", (unsigned long) size);
42 abort();
43 }
44 return p;
45}
46
51#define FREE_PTR(PTR) do { \
52 if (PTR != NULL) \
53 free(PTR); \
54 PTR = NULL; \
55} while (0)
56
57#endif
char * my_strdup(const char *str, size_t len)
Definition mem.c:22