From 8468b9a199358d76c2e4d1a0ef836373d5fc08cd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Aug 2015 23:55:59 +0000 Subject: Fix lilv_realpath() on pre-POSIX-2008 systems. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5705 a436a847-0d15-0410-975c-d299462d15a1 --- NEWS | 3 ++- src/util.c | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 69628d3..2b05a30 100644 --- a/NEWS +++ b/NEWS @@ -16,10 +16,11 @@ lilv (0.21.3) unstable; * Preserve absolute paths in state if no link directory is given * Fix a few minor/unlikely memory errors * Configure based on compiler target OS for cross-compilation + * Fix lilv_realpath() on pre-POSIX-2008 systems * Windows fixes (thanks John Emmas) * Minor documentation improvements - -- David Robillard Mon, 16 Mar 2015 03:24:05 -0400 + -- David Robillard Thu, 13 Aug 2015 19:55:27 -0400 lilv (0.20.0) stable; diff --git a/src/util.c b/src/util.c index 31c9238..029cb92 100644 --- a/src/util.c +++ b/src/util.c @@ -14,8 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define _POSIX_C_SOURCE 1 /* for fileno */ -#define _BSD_SOURCE 1 /* for realpath, symlink */ +#define _POSIX_C_SOURCE 200809L /* for fileno */ +#define _BSD_SOURCE 1 /* for realpath, symlink */ #ifdef __APPLE__ # define _DARWIN_C_SOURCE 1 /* for flock */ @@ -430,13 +430,23 @@ lilv_get_latest_copy(const char* path, const char* copy_path) char* lilv_realpath(const char* path) { -#ifdef _WIN32 +#if defined(_WIN32) char* out = (char*)malloc(MAX_PATH); GetFullPathName(path, MAX_PATH, out, NULL); return out; -#else +#elif _POSIX_VERSION >= 200809L char* real_path = realpath(path, NULL); return real_path ? real_path : lilv_strdup(path); +#else + // OSX <= 105, if anyone cares. I sure don't. + char* out = (char*)malloc(PATH_MAX); + char* real_path = realpath(path, out); + if (!real_path) { + free(out); + return lilv_strdup(path); + } else { + return real_path; + } #endif } -- cgit v1.2.1