MSVC: compat: implement realpath()
diff --git a/CMakeModules/UseCompat.cmake b/CMakeModules/UseCompat.cmake
index f9d98a0..31bd59f 100644
--- a/CMakeModules/UseCompat.cmake
+++ b/CMakeModules/UseCompat.cmake
@@ -51,6 +51,8 @@
     check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
     check_symbol_exists(timezone time.h HAVE_TIME_H_TIMEZONE)
 
+    check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
+
     unset(CMAKE_REQUIRED_DEFINITIONS)
     unset(CMAKE_REQUIRED_LIBRARIES)
 
diff --git a/compat/compat.c b/compat/compat.c
index d75b961..d721616 100644
--- a/compat/compat.c
+++ b/compat/compat.c
@@ -250,3 +250,21 @@
 }
 
 #endif
+
+#ifndef HAVE_REALPATH
+#ifdef _WIN32
+char *
+realpath(const char *path, char *resolved_path)
+{
+    char *resolved = _fullpath(resolved_path, path, PATH_MAX);
+
+    if ((_access(resolved, 0) == -1) && (errno == ENOENT)) {
+        return NULL;
+    }
+    return resolved;
+}
+
+#else
+#error No realpath() implementation for this platform is available.
+#endif
+#endif
diff --git a/compat/compat.h.in b/compat/compat.h.in
index 3a14969..d84eeb4 100644
--- a/compat/compat.h.in
+++ b/compat/compat.h.in
@@ -61,6 +61,7 @@
 #cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK
 #cmakedefine HAVE_TM_GMTOFF
 #cmakedefine HAVE_TIME_H_TIMEZONE
+#cmakedefine HAVE_REALPATH
 
 #ifndef bswap64
 #define bswap64(val) \
@@ -158,4 +159,8 @@
 int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
 #endif
 
+#ifndef HAVE_REALPATH
+char *realpath(const char *path, char *resolved_path);
+#endif
+
 #endif /* _COMPAT_H_ */