aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-29 09:38:08 +0200
committerMax Kellermann <max@duempel.org>2008-08-29 09:38:08 +0200
commitf42de62aa23dc238a767a6fcf0e92fd2c5f3a8f3 (patch)
tree9803723ce6923b2b12a80e0733b359b32cafd801 /src/utils.h
parent8811c0e05943edbcb3d7203ef4f61ec89423718a (diff)
downloadmpd-f42de62aa23dc238a767a6fcf0e92fd2c5f3a8f3.tar.gz
mpd-f42de62aa23dc238a767a6fcf0e92fd2c5f3a8f3.tar.xz
mpd-f42de62aa23dc238a767a6fcf0e92fd2c5f3a8f3.zip
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.
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h13
1 files changed, 13 insertions, 0 deletions
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);