summaryrefslogtreecommitdiff
path: root/windows
diff options
context:
space:
mode:
Diffstat (limited to 'windows')
-rw-r--r--windows/gui.c82
-rw-r--r--windows/gui.h1
-rw-r--r--windows/main.c1
3 files changed, 59 insertions, 25 deletions
diff --git a/windows/gui.c b/windows/gui.c
index 0af54ee62..0be75e1e8 100644
--- a/windows/gui.c
+++ b/windows/gui.c
@@ -43,6 +43,7 @@
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
+#include "utils/file.h"
#include "windows/window.h"
#include "windows/about.h"
@@ -1808,42 +1809,75 @@ nsws_create_main_class(HINSTANCE hinstance) {
}
/**
- * Return the filename part of a full path
+ * Generate a windows path from one or more component elemnts.
*
- * \param path full path and filename
- * \return filename (will be freed with free())
+ * If a string is allocated it must be freed by the caller.
+ *
+ * @param[in,out] str pointer to string pointer if this is NULL enough
+ * storage will be allocated for the complete path.
+ * @param[in,out] size The size of the space available if \a str not
+ * NULL on input and if not NULL set to the total
+ * output length on output.
+ * @param[in] nemb The number of elements.
+ * @param[in] ... The elements of the path as string pointers.
+ * @return NSERROR_OK and the complete path is written to str
+ * or error code on faliure.
*/
-static char *filename_from_path(char *path)
+static nserror windows_mkpath(char **str, size_t *size, size_t nelm, va_list ap)
{
- char *leafname;
-
- leafname = strrchr(path, '\\');
- if (!leafname)
- leafname = path;
- else
- leafname += 1;
-
- return strdup(leafname);
+ return vsnstrjoin(str, size, '\\', nelm, ap);
}
/**
- * Add a path component/filename to an existing path
+ * Get the basename of a file using windows path handling.
+ *
+ * This gets the last element of a path and returns it.
*
- * \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
+ * @param[in] path The path to extract the name from.
+ * @param[in,out] str Pointer to string pointer if this is NULL enough
+ * storage will be allocated for the path element.
+ * @param[in,out] size The size of the space available if \a
+ * str not NULL on input and set to the total
+ * output length on output.
+ * @return NSERROR_OK and the complete path is written to str
+ * or error code on faliure.
*/
-static bool path_add_part(char *path, int length, const char *newpart)
+static nserror windows_basename(const char *path, char **str, size_t *size)
{
- if(path[strlen(path) - 1] != '\\')
- strncat(path, "\\", length);
+ const char *leafname;
+ char *fname;
- strncat(path, newpart, length);
+ if (path == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
- return true;
+ leafname = strrchr(path, '\\');
+ if (!leafname) {
+ leafname = path;
+ } else {
+ leafname += 1;
+ }
+
+ fname = strdup(leafname);
+ if (fname == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ *str = fname;
+ if (size != NULL) {
+ *size = strlen(fname);
+ }
+ return NSERROR_OK;
}
+/* default to using the posix file handling */
+static struct gui_file_table file_table = {
+ .mkpath = windows_mkpath,
+ .basename = windows_basename,
+};
+
+struct gui_file_table *win32_file_table = &file_table;
+
static struct gui_window_table window_table = {
.create = gui_window_create,
.destroy = gui_window_destroy,
@@ -1876,8 +1910,6 @@ struct gui_clipboard_table *win32_clipboard_table = &clipboard_table;
static struct gui_fetch_table 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/windows/gui.h b/windows/gui.h
index d8e1b1d0b..82ae83642 100644
--- a/windows/gui.h
+++ b/windows/gui.h
@@ -24,6 +24,7 @@
#include "desktop/gui.h"
#include "windows/localhistory.h"
+struct gui_file_table *win32_file_table;
extern struct gui_window_table *win32_window_table;
extern struct gui_clipboard_table *win32_clipboard_table;
extern struct gui_fetch_table *win32_fetch_table;
diff --git a/windows/main.c b/windows/main.c
index 19cd44a43..22cb5207c 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -111,6 +111,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
.clipboard = win32_clipboard_table,
.download = win32_download_table,
.fetch = win32_fetch_table,
+ .file = win32_file_table,
.utf8 = win32_utf8_table,
};
win32_fetch_table->get_resource_url = gui_get_resource_url;