summaryrefslogtreecommitdiff
path: root/atari
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-05-07 16:14:18 +0100
committerVincent Sanders <vince@kyllikki.org>2014-05-07 16:24:51 +0100
commitc56642819eed87431dff3446fe111f7f3eefaa7d (patch)
tree397126ca4baac425f9c1c44f3d5c56c681e2c4fe /atari
parentc1e2da80dfa62793ea107cf12408c814e268a54b (diff)
downloadnetsurf-c56642819eed87431dff3446fe111f7f3eefaa7d.tar.gz
netsurf-c56642819eed87431dff3446fe111f7f3eefaa7d.tar.bz2
add file operations table and make all frontends use it.
This rationalises the path construction and basename file operations. The default implementation is POSIX which works for all frontends except windows, riscos and amiga which have differeing path separators and rules. These implementations are significantly more robust than the previous nine implementations and also do not use unsafe strncpy or buffers with arbitrary length limits. These implementations also carry full documentation comments.
Diffstat (limited to 'atari')
-rw-r--r--atari/gui.c24
-rwxr-xr-xatari/misc.c34
-rwxr-xr-xatari/misc.h2
3 files changed, 4 insertions, 56 deletions
diff --git a/atari/gui.c b/atari/gui.c
index c275bfdc4..0979f2974 100644
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -114,28 +114,6 @@ short aes_msg_out[8];
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy);
static void gui_window_set_url(struct gui_window *w, const char *url);
-/**
- * Return the filename part of a full path
- *
- * \param path full path and filename
- * \return filename (will be freed with free())
- */
-static char *filename_from_path(char *path)
-{
- char *leafname;
-
- leafname = strrchr(path, '\\');
- if( !leafname )
- leafname = strrchr(path, '/');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
-}
-
-
static void gui_poll(bool active)
{
@@ -1071,8 +1049,6 @@ static struct gui_clipboard_table atari_clipboard_table = {
};
static struct gui_fetch_table atari_fetch_table = {
- .filename_from_path = filename_from_path,
- .path_add_part = path_add_part,
.filetype = fetch_filetype,
.path_to_url = path_to_url,
.url_to_path = url_to_path,
diff --git a/atari/misc.c b/atari/misc.c
index ca9e993d9..a8eff288b 100755
--- a/atari/misc.c
+++ b/atari/misc.c
@@ -70,24 +70,6 @@ void die(const char *error)
exit(1);
}
-/**
- * Add a path component/filename to an existing path
- *
- * \param path buffer containing path + free space
- * \param length length of buffer "path"
- * \param newpart string containing path component to add to path
- * \return true on success
- */
-
-bool path_add_part(char *path, int length, const char *newpart)
-{
- if(path[strlen(path) - 1] != '/')
- strncat(path, "/", length);
-
- strncat(path, newpart, length);
-
- return true;
-}
struct gui_window * find_guiwin_by_aes_handle(short handle){
@@ -242,25 +224,17 @@ hlcache_handle *load_icon(const char *name, hlcache_handle_callback cb,
if (!strncmp(name, "file://", 7)) {
icon_url = name;
} else {
- char *native_path;
+ char *native_path = NULL;
if (icons_dir == NULL)
return NULL;
- /* path + separator + leafname + '\0' */
- len = strlen(icons_dir) + 1 + strlen(name) + 1;
- native_path = malloc(len);
- if (native_path == NULL) {
- LOG(("malloc failed"));
- warn_user("NoMemory", 0);
+ err = netsurf_mkpath(&native_path, NULL, 2, icons_dir, name);
+ if (err != NSERROR_OK) {
+ warn_user(messages_get_errorcode(err));
return NULL;
}
- /* Build native path */
- memcpy(native_path, icons_dir,
- strlen(icons_dir) + 1);
- path_add_part(native_path, len, name);
-
/* Convert native path to URL */
url = path_to_url(native_path);
diff --git a/atari/misc.h b/atari/misc.h
index 1bb5e8131..8d1719ce8 100755
--- a/atari/misc.h
+++ b/atari/misc.h
@@ -66,6 +66,4 @@ const char * file_select(const char * title, const char * name);
*/
long nkc_to_input_key(short nkc, long * ucs4_out);
-bool path_add_part(char *path, int length, const char *newpart);
-
#endif