summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-08-13 23:55:59 +0000
committerDavid Robillard <d@drobilla.net>2015-08-13 23:55:59 +0000
commit8468b9a199358d76c2e4d1a0ef836373d5fc08cd (patch)
tree48466f2f44657b4c4e98dc67c41b96afbd89a7b5
parent1cf47cc42caff696f77a49dc46370718bb7755dd (diff)
downloadlilv-8468b9a199358d76c2e4d1a0ef836373d5fc08cd.tar.gz
lilv-8468b9a199358d76c2e4d1a0ef836373d5fc08cd.tar.bz2
lilv-8468b9a199358d76c2e4d1a0ef836373d5fc08cd.zip
Fix lilv_realpath() on pre-POSIX-2008 systems.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5705 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--NEWS3
-rw-r--r--src/util.c18
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 <d@drobilla.net> Mon, 16 Mar 2015 03:24:05 -0400
+ -- David Robillard <d@drobilla.net> 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
}