From b9d8a5880abc537f3f293d2b3c190bf9361cec76 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sat, 9 Jan 2010 13:43:29 +0100 Subject: [PATCH] Introduce m_realpath() to replace realpath(path, NULL) --- src/misc.c | 22 ++++++++++++++++++++++ src/misc.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/misc.c b/src/misc.c index ede86509..0cadf30c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "logger.h" #include "misc.h" @@ -101,6 +102,27 @@ safe_atol(const char *str, long *val) return 0; } +char * +m_realpath(const char *pathname) +{ + char buf[PATH_MAX]; + char *ret; + + ret = realpath(pathname, buf); + if (!ret) + return NULL; + + ret = strdup(buf); + if (!ret) + { + DPRINTF(E_LOG, L_MISC, "Out of memory for realpath\n"); + + return NULL; + } + + return ret; +} + uint32_t djb_hash(void *data, size_t len) { diff --git a/src/misc.h b/src/misc.h index b0b71b01..5aea3518 100644 --- a/src/misc.h +++ b/src/misc.h @@ -10,6 +10,9 @@ safe_atoi(const char *str, int *val); int safe_atol(const char *str, long *val); +char * +m_realpath(const char *pathname); + uint32_t djb_hash(void *data, size_t len);