summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2010-03-21 13:32:59 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2010-03-21 13:32:59 +0000
commit033b5d815a19a05441a99cdc744a6a8752d191cc (patch)
treead0aadcb6bcfd10362fbe7f266906ecd9fa8fde3 /riscos
parent1f67fed782a2c20e5b8222ef5fb9867f036ff054 (diff)
downloadnetsurf-033b5d815a19a05441a99cdc744a6a8752d191cc.tar.gz
netsurf-033b5d815a19a05441a99cdc744a6a8752d191cc.tar.bz2
Move code which extracts the filename from a given path into frontend.
svn path=/trunk/netsurf/; revision=10139
Diffstat (limited to 'riscos')
-rw-r--r--riscos/gui.c36
1 files changed, 36 insertions, 0 deletions
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;
+}