From f42de62aa23dc238a767a6fcf0e92fd2c5f3a8f3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2008 09:38:08 +0200 Subject: 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. --- src/utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utils.h b/src/utils.h index 6a6e562cf..77e143702 100644 --- a/src/utils.h +++ b/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); -- cgit v1.2.3