From d818995cf91c9d632b2446022854529ac0f02835 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 3 Mar 2018 20:27:49 -0500 Subject: Add serd_realpath() utility function --- src/serd_internal.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/serd_internal.h') diff --git a/src/serd_internal.h b/src/serd_internal.h index cfcdc82c..bd30b8c4 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -18,12 +18,15 @@ #define SERD_INTERNAL_H #define _POSIX_C_SOURCE 200809L /* for posix_memalign and posix_fadvise */ +#define _XOPEN_SOURCE 500 /* for realpath */ #include #include #include +#include #include #include +#include #include #include "serd/serd.h" @@ -73,6 +76,19 @@ serd_bufalloc(size_t size) #endif } +static inline const uint8_t* +serd_realpath(const uint8_t* path) +{ +#if defined(_WIN32) + static uint8_t real[MAX_PATH]; + GetFullPathName(path, MAX_PATH, real, NULL); + return real; +#else + static char real[PATH_MAX]; + return (const uint8_t*)realpath((const char*)path, real); +#endif +} + /* Byte source */ typedef struct { -- cgit v1.2.1