Summary Files Commits Branches @commit @diff @stats
path: root / uri.c
diff options
context:
space:
mode:
1 files changed, 20 insertions, 2 deletions
-rw-r--r--uri.c22
diff --git a/uri.c b/uri.c
index 6843e4a..912bf86 100644
--- a/uri.c
+++ b/uri.c
@@ -4,19 +4,37 @@
#include "uri.h"
-#include <glib.h> /* g_strcmp0() */
+#include <glib.h> /* g_strcmp0(), g_uri_parse_scheme(), g_strdup_printf */
+#include <stdlib.h> /* realpath(), free() */
#include <unistd.h> /* access() */
const gchar *
badwolf_ensure_uri_scheme(const gchar *text, gboolean try_file)
{
const gchar *fallback = "about:blank";
+ char *path = NULL;
if(g_strcmp0(text, "") <= 0) return fallback;
if(g_uri_parse_scheme(text)) return text;
- if(try_file && (access(text, R_OK) == 0)) return g_strdup_printf("file://%s", text);
+ if(try_file)
+ {
+ path = realpath(text, NULL);
+ gchar *f = NULL;
+
+ if(path != NULL)
+ {
+ if(access(path, R_OK) == 0)
+ {
+ f = g_strdup_printf("file://%s", path);
+ }
+
+ free(path);
+
+ return f;
+ }
+ }
return g_strdup_printf("http://%s", text);
}