added xfree() which takes a const pointer
Unfortunately, the C standard postulates that the argument to free() must be non-const. This does not makes sense, and virtually prevents every pointer which must be freed at some time to be non-const. Use the deconst hack (sorry for that) to allow us to free constant pointers.
This commit is contained in:
parent
8811c0e059
commit
f42de62aa2
13
src/utils.h
13
src/utils.h
@ -76,6 +76,19 @@ mpd_malloc void *xrealloc(void *ptr, size_t size);
|
||||
|
||||
mpd_malloc void *xcalloc(size_t nmemb, size_t size);
|
||||
|
||||
/**
|
||||
* free a const pointer - unfortunately free() expects a non-const
|
||||
* pointer, for whatever reason
|
||||
*/
|
||||
static inline void xfree(const void *p)
|
||||
{
|
||||
union {
|
||||
const void *in;
|
||||
void *out;
|
||||
} deconst = { .in = p };
|
||||
free(deconst.out);
|
||||
}
|
||||
|
||||
char *parsePath(char *path);
|
||||
|
||||
int set_nonblocking(int fd);
|
||||
|
Loading…
Reference in New Issue
Block a user