diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2010-09-11 18:47:36 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2010-09-11 18:47:36 +0000 |
commit | faca1687ceac7c07daf5478071361fe98aa4cafe (patch) | |
tree | c576e41756deed0ae9a1d75aa08e9c3fd0ae61c2 | |
parent | 4cbb19f2184bc69c408bfffd32b70390f634314c (diff) | |
download | netsurf-faca1687ceac7c07daf5478071361fe98aa4cafe.tar.gz netsurf-faca1687ceac7c07daf5478071361fe98aa4cafe.tar.bz2 |
hell with it, heres a version which should result in fewer portability complaints
svn path=/trunk/netsurf/; revision=10756
-rw-r--r-- | Docs/BUILDING-GTK | 2 | ||||
-rw-r--r-- | content/fetchers/fetch_file.c | 76 | ||||
-rw-r--r-- | framebuffer/findfile.c | 18 | ||||
-rw-r--r-- | gtk/gtk_gui.c | 18 | ||||
-rw-r--r-- | riscos/gui.c | 33 | ||||
-rw-r--r-- | utils/config.h | 15 |
6 files changed, 75 insertions, 87 deletions
diff --git a/Docs/BUILDING-GTK b/Docs/BUILDING-GTK index 4f4d9dbe0..714826c94 100644 --- a/Docs/BUILDING-GTK +++ b/Docs/BUILDING-GTK @@ -67,7 +67,7 @@ Debian-like OS: $ apt-get install libglade2-dev libcurl3-dev libxml2-dev libmng-dev - $ apt-get install librsvg2-dev + $ apt-get install librsvg2-dev liblcms1-dev Recent OS versions might need libcurl4-dev instead of libcurl3-dev but note that when it has not been built with OpenSSL, the SSL_CTX is not diff --git a/content/fetchers/fetch_file.c b/content/fetchers/fetch_file.c index 19270c70a..8537d1805 100644 --- a/content/fetchers/fetch_file.c +++ b/content/fetchers/fetch_file.c @@ -128,22 +128,13 @@ fetch_file_setup(struct fetch *fetchh, const char **headers) { struct fetch_file_context *ctx; - char *path; - url_func_result res; /* result from url routines */ ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) return NULL; - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - free(ctx); - return NULL; - } - - res = url_unescape(path, &ctx->path); - free(path); - if (res != URL_FUNC_OK) { + ctx->path = url_to_path(url); + if (ctx->path == NULL) { free(ctx); return NULL; } @@ -220,7 +211,7 @@ fetch_file_process_error_aborted: /** Process object as a regular file */ static void fetch_file_process_plain(struct fetch_file_context *ctx, - int fd, struct stat *fdstat) + struct stat *fdstat) { char *buf; size_t buf_size; @@ -228,6 +219,26 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx, ssize_t tot_read = 0; ssize_t res; + int fd; /**< The file descriptor of the object */ + fd = open(ctx->path, O_RDONLY); + if (fd < 0) { + /* process errors as appropriate */ + switch (errno) { + case EACCES: + fetch_file_process_error(ctx, 403); + break; + + case ENOENT: + fetch_file_process_error(ctx, 404); + break; + + default: + fetch_file_process_error(ctx, 500); + break; + } + return; + } + /* set buffer size */ buf_size = fdstat->st_size; if (buf_size > FETCH_FILE_MAX_BUF_SIZE) @@ -351,7 +362,7 @@ static char *gen_nice_title(char *path) static void fetch_file_process_dir(struct fetch_file_context *ctx, - int fd, struct stat *fdstat) + struct stat *fdstat) { char buffer[1024]; /* Output buffer */ bool even = false; /* formatting flag */ @@ -367,18 +378,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx, char timebuf[64]; /* buffer for time text */ char urlpath[PATH_MAX]; /* buffer for leaf entry path */ -#if defined(HAVE_FDOPENDIR) - scandir = fdopendir(fd); -#else - /* this poses the possibility of a race where the directory - * has been removed from the namespace or resources for more - * fd are now unavailable between the previous open() and this - * call. - */ - close(fd); scandir = opendir(ctx->path); -#endif - if (scandir == NULL) { fetch_file_process_error(ctx, 500); return; @@ -518,46 +518,24 @@ fetch_file_process_dir_aborted: /* process a file fetch */ static void fetch_file_process(struct fetch_file_context *ctx) { - int fd; /**< The file descriptor of the object */ struct stat fdstat; /**< The objects stat */ - fd = open(ctx->path, O_RDONLY); - if (fd < 0) { - /* process errors as appropriate */ - switch (errno) { - case EACCES: - fetch_file_process_error(ctx, 403); - break; - - case ENOENT: - fetch_file_process_error(ctx, 404); - break; - - default: - fetch_file_process_error(ctx, 500); - break; - } - return; - } - - if (fstat(fd, &fdstat) != 0) { + if (stat(ctx->path, &fdstat) != 0) { /* process errors as appropriate */ - close(fd); fetch_file_process_error(ctx, 500); return; } if (S_ISDIR(fdstat.st_mode)) { /* directory listing */ - fetch_file_process_dir(ctx, fd, &fdstat); + fetch_file_process_dir(ctx, &fdstat); return; } else if (S_ISREG(fdstat.st_mode)) { /* regular file */ - fetch_file_process_plain(ctx, fd, &fdstat); + fetch_file_process_plain(ctx, &fdstat); return; } else { /* unhandled type of file */ - close(fd); fetch_file_process_error(ctx, 501); } diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c index a00f0f835..caa910005 100644 --- a/framebuffer/findfile.c +++ b/framebuffer/findfile.c @@ -47,14 +47,22 @@ char *path_to_url(const char *path) char *url_to_path(const char *url) { - char *url_path = curl_unescape(url, 0); char *path; + char *respath; + url_func_result res; /* result from url routines */ - /* return the absolute path including leading / */ - path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); - curl_free(url_path); + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + return NULL; + } + + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } - return path; + return respath; } /** diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index a9e428b19..24070bb47 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -867,14 +867,22 @@ char *path_to_url(const char *path) char *url_to_path(const char *url) { - char *url_path = curl_unescape(url, 0); char *path; + char *respath; + url_func_result res; /* result from url routines */ - /* return the absolute path including leading / */ - path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); - curl_free(url_path); + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + return NULL; + } - return path; + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { + return NULL; + } + + return respath; } diff --git a/riscos/gui.c b/riscos/gui.c index 5d032f3ef..10f5eaaea 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2112,32 +2112,41 @@ char *path_to_url(const char *path) char *url_to_path(const char *url) { - char *temp_name, *r; - char *filename; + char *path; + char *respath; + url_func_result res; /* result from url routines */ + char *r; - if (strncmp(url, FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN)) + res = url_path(url, &path); + if (res != URL_FUNC_OK) { + warn_user("NoMemory", 0); return NULL; + } - temp_name = curl_unescape(url + 7, strlen(url) - 7); - - if (!temp_name) { - warn_user("NoMemory", 0); + res = url_unescape(path, &respath); + free(path); + if (res != URL_FUNC_OK) { return NULL; } - filename = malloc(strlen(temp_name) + 100); + /* RISC OS path should not be more than 100 characters longer */ + filename = malloc(strlen(respath) + 100); if (!filename) { - curl_free(temp_name); + free(respath); warn_user("NoMemory", 0); return NULL; } - r = __riscosify(temp_name, 0, __RISCOSIFY_NO_SUFFIX, - filename, strlen(temp_name) + 100, 0); + + r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX, + filename, strlen(respath) + 100, 0); + + free(respath); if (r == 0) { + free(filename); LOG(("__riscosify failed")); return NULL; } - curl_free(temp_name); + return filename; } diff --git a/utils/config.h b/utils/config.h index 92d0e64b9..adf2db103 100644 --- a/utils/config.h +++ b/utils/config.h @@ -38,21 +38,6 @@ char *strndup(const char *s, size_t n); char *strcasestr(const char *haystack, const char *needle); #endif -/* fdopendir is actually present on most unix systems but unless - * _POSIX_C_SOURCE is set to 2008 it is not declared in the system - * headers. It is unavailable on RISC OS which requires fallback code - */ -#if (_POSIX_C_SOURCE - 0) >= 200809L -#define HAVE_FDOPENDIR -#else -#if defined(riscos) || defined(__amigaos4__) -#undef HAVE_FDOPENDIR -#else -#define HAVE_FDOPENDIR -DIR *fdopendir(int fd); -#endif -#endif - /* For some reason, UnixLib defines this unconditionally. * Assume we're using UnixLib if building for RISC OS. */ #if (defined(_GNU_SOURCE) || defined(riscos)) |