aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index 566e8839..76c12235 100644
--- a/src/node.c
+++ b/src/node.c
@@ -14,6 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define _XOPEN_SOURCE 600 /* for realpath */
+
#include "node.h"
#include "namespaces.h"
@@ -24,6 +26,11 @@
#include "exess/exess.h"
#include "serd/serd.h"
+#ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN 1
+# include <windows.h>
+#endif
+
#include <assert.h>
#include <float.h>
#include <math.h>
@@ -539,6 +546,32 @@ is_uri_path_char(const char c)
}
}
+static char*
+serd_realpath(const char* const path)
+{
+ if (!path) {
+ return NULL;
+ }
+
+#ifdef _WIN32
+ const DWORD size = GetFullPathName(path, 0, NULL, NULL);
+ if (size == 0) {
+ return NULL;
+ }
+
+ char* const out = (char*)calloc(size, 1);
+ const DWORD ret = GetFullPathName(path, MAX_PATH, out, NULL);
+ if (ret == 0 || ret >= size) {
+ free(out);
+ return NULL;
+ }
+
+ return out;
+#else
+ return realpath(path, NULL);
+#endif
+}
+
SerdNode*
serd_new_file_uri(const SerdStringView path, const SerdStringView hostname)
{
@@ -586,6 +619,20 @@ serd_new_file_uri(const SerdStringView path, const SerdStringView hostname)
return node;
}
+SerdNode*
+serd_new_real_file_uri(const char* const path, const char* const hostname)
+{
+ char* const real_path = serd_realpath(path);
+ if (!real_path) {
+ return NULL;
+ }
+
+ SerdNode* const node = serd_new_file_uri(SERD_MEASURE_STRING(real_path),
+ SERD_MEASURE_STRING(hostname));
+ free(real_path);
+ return node;
+}
+
typedef size_t (*SerdWriteLiteralFunc)(const void* const user_data,
const size_t buf_size,
char* const buf);