summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xamiga/misc.c15
-rw-r--r--beos/beos_gui.cpp20
-rw-r--r--content/fetchers/fetch_curl.c35
-rw-r--r--framebuffer/misc.c20
-rw-r--r--gtk/gtk_gui.c20
-rw-r--r--riscos/gui.c36
-rw-r--r--utils/utils.h2
-rw-r--r--windows/misc.c20
8 files changed, 134 insertions, 34 deletions
diff --git a/amiga/misc.c b/amiga/misc.c
index cee6aa688..f492fcf8a 100755
--- a/amiga/misc.c
+++ b/amiga/misc.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2008, 2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
+ * Copyright 2008-2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -24,6 +24,7 @@
#include "utils/messages.h"
#include <stdlib.h>
#include <curl/curl.h>
+#include "utils/utils.h"
void warn_user(const char *warning, const char *detail)
{
@@ -84,6 +85,18 @@ char *path_to_url(const char *path)
}
/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ return strdup(FilePart(path));
+}
+
+/**
* returns a string without escape chars or |M chars.
* (based on remove_underscores from utils.c)
* \param translate true to insert a linebreak where there was |M,
diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp
index 3f83a8dcb..6c05bc401 100644
--- a/beos/beos_gui.cpp
+++ b/beos/beos_gui.cpp
@@ -1160,3 +1160,23 @@ static void *myrealloc(void *ptr, size_t len, void *pw)
{
return realloc(ptr, len);
}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}
diff --git a/content/fetchers/fetch_curl.c b/content/fetchers/fetch_curl.c
index e11829b46..ca2d86845 100644
--- a/content/fetchers/fetch_curl.c
+++ b/content/fetchers/fetch_curl.c
@@ -1219,36 +1219,9 @@ fetch_curl_post_convert(struct form_successful_control *control)
for (; control; control = control->next) {
if (control->file) {
char *leafname = 0;
-#ifdef riscos
- char *temp;
- int leaflen;
-
- temp = strrchr(control->value, '.');
- if (!temp)
- temp = control->value; /* already leafname */
- else
- temp += 1;
-
- leaflen = strlen(temp);
-
- leafname = malloc(leaflen + 1);
- if (!leafname) {
- LOG(("malloc failed"));
- continue;
- }
- memcpy(leafname, temp, leaflen + 1);
-
- /* and s/\//\./g */
- for (temp = leafname; *temp; temp++)
- if (*temp == '/')
- *temp = '.';
-#else
- leafname = strrchr(control->value, '/') ;
- if (!leafname)
- leafname = control->value;
- else
- leafname += 1;
-#endif
+
+ leafname = filename_from_path(control->value);
+
/* We have to special case filenames of "", so curl
* a) actually attempts the fetch and
* b) doesn't attempt to open the file ""
@@ -1288,9 +1261,7 @@ fetch_curl_post_convert(struct form_successful_control *control)
control->value));
free(mimetype);
}
-#ifdef riscos
free(leafname);
-#endif
}
else {
code = curl_formadd(&post, &last,
diff --git a/framebuffer/misc.c b/framebuffer/misc.c
index 20c676324..c5f367019 100644
--- a/framebuffer/misc.c
+++ b/framebuffer/misc.c
@@ -44,3 +44,23 @@ char *url_to_path(const char *url)
{
return strdup(url + 5);
}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}
diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c
index 163972fc7..0251e173f 100644
--- a/gtk/gtk_gui.c
+++ b/gtk/gtk_gui.c
@@ -920,3 +920,23 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
key->keyval);
}
}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '/');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}
diff --git a/riscos/gui.c b/riscos/gui.c
index 64276b36b..a1c1980e2 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -2417,3 +2417,39 @@ void PDF_Password(char **owner_pass, char **user_pass, char *path)
/*TODO:this waits to be written, until then no PDF encryption*/
*owner_pass = NULL;
}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ char *leafname;
+ char *temp;
+ int leaflen;
+
+ temp = strrchr(path, '.');
+ if (!temp)
+ temp = path; /* already leafname */
+ else
+ temp += 1;
+
+ leaflen = strlen(temp);
+
+ leafname = malloc(leaflen + 1);
+ if (!leafname) {
+ LOG(("malloc failed"));
+ continue;
+ }
+ memcpy(leafname, temp, leaflen + 1);
+
+ /* and s/\//\./g */
+ for (temp = leafname; *temp; temp++)
+ if (*temp == '/')
+ *temp = '.';
+
+ return leafname;
+}
diff --git a/utils/utils.h b/utils/utils.h
index c6b07c6b6..f58a2632b 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -108,5 +108,5 @@ query_id query_user(const char *query, const char *detail,
const query_callback *cb, void *pw, const char *yes, const char *no);
void query_close(query_id);
void PDF_Password(char **owner_pass, char **user_pass, char *path);
-
+char *filename_from_path(char *path);
#endif
diff --git a/windows/misc.c b/windows/misc.c
index 5eebaa383..002297665 100644
--- a/windows/misc.c
+++ b/windows/misc.c
@@ -50,3 +50,23 @@ char *url_to_path(const char *url)
{
return strdup(url + 5);
}
+
+/**
+ * Return the filename part of a full path
+ *
+ * \param path full path and filename
+ * \return filename (will be freed with free())
+ */
+
+char *filename_from_path(char *path)
+{
+ char *leafname;
+
+ leafname = strrchr(path, '\\');
+ if (!leafname)
+ leafname = path;
+ else
+ leafname += 1;
+
+ return strdup(leafname);
+}