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:
Max Kellermann 2008-08-29 09:38:08 +02:00
parent 8811c0e059
commit f42de62aa2

View File

@ -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);