From 448b0275ae4d62b31f64e3c6399d4fb5a045315c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 16 Apr 2010 23:56:53 +0000 Subject: Fix file: handling on risc os, gtk, windows and framebuffer frontends svn path=/trunk/netsurf/; revision=10419 --- framebuffer/findfile.c | 27 +++++++++++++++++++++++---- framebuffer/misc.c | 5 ----- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'framebuffer') diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c index 64d96fcb4..a00f0f835 100644 --- a/framebuffer/findfile.c +++ b/framebuffer/findfile.c @@ -23,6 +23,8 @@ #include #include +#include + #include "utils/log.h" #include "utils/url.h" @@ -30,12 +32,29 @@ char *path_to_url(const char *path) { - char *r = malloc(strlen(path) + FILE_SCHEME_PREFIX_LEN + 1); + int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + char *url = malloc(urllen); + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } + + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; +} + + +char *url_to_path(const char *url) +{ + char *url_path = curl_unescape(url, 0); + char *path; - strcpy(r, FILE_SCHEME_PREFIX); - strcat(r, path); + /* return the absolute path including leading / */ + path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); + curl_free(url_path); - return r; + return path; } /** diff --git a/framebuffer/misc.c b/framebuffer/misc.c index c5f367019..5e351f517 100644 --- a/framebuffer/misc.c +++ b/framebuffer/misc.c @@ -40,10 +40,6 @@ bool cookies_update(const char *domain, const struct cookie_data *data) return true; } -char *url_to_path(const char *url) -{ - return strdup(url + 5); -} /** * Return the filename part of a full path @@ -51,7 +47,6 @@ char *url_to_path(const char *url) * \param path full path and filename * \return filename (will be freed with free()) */ - char *filename_from_path(char *path) { char *leafname; -- cgit v1.2.3