Tuesday, 29 October 2024

[netsurf-dev] [PATCH 1/3] Return nserror in most filepath utility functions

From: Olivier Valentin <valentio@free.fr>

---
frontends/framebuffer/fetch.c | 3 +-
frontends/framebuffer/font_freetype.c | 4 +-
frontends/framebuffer/gui.c | 4 +-
frontends/gtk/fetch.c | 3 +-
frontends/gtk/gui.c | 2 +-
frontends/gtk/resources.c | 3 +-
frontends/monkey/fetch.c | 3 +-
frontends/monkey/main.c | 4 +-
frontends/windows/fetch.c | 3 +-
frontends/windows/main.c | 11 ++--
utils/filepath.c | 75 +++++++++++++++------------
utils/filepath.h | 35 ++++++-------
12 files changed, 78 insertions(+), 72 deletions(-)

diff --git a/frontends/framebuffer/fetch.c b/frontends/framebuffer/fetch.c
index 23cbb4f21..d58a82205 100644
--- a/frontends/framebuffer/fetch.c
+++ b/frontends/framebuffer/fetch.c
@@ -54,7 +54,8 @@ static nsurl *get_resource_url(const char *path)
if (strcmp(path, "favicon.ico") == 0)
path = "favicon.png";

- netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
+ if (filepath_sfind(respaths, buf, path) == NSERROR_OK)
+ netsurf_path_to_nsurl(buf, &url);

return url;
}
diff --git a/frontends/framebuffer/font_freetype.c b/frontends/framebuffer/font_freetype.c
index 3912821f7..0c43a95ee 100644
--- a/frontends/framebuffer/font_freetype.c
+++ b/frontends/framebuffer/font_freetype.c
@@ -120,15 +120,13 @@ fb_new_face(const char *option, const char *resname, const char *fontname)
fb_faceid_t *newf;
FT_Error error;
FT_Face aface;
- char buf[PATH_MAX];

newf = calloc(1, sizeof(fb_faceid_t));

if (option != NULL) {
newf->fontfile = strdup(option);
} else {
- filepath_sfind(respaths, buf, fontname);
- newf->fontfile = strdup(buf);
+ filepath_find(respaths, fontname, &newf->fontfile);
}

error = FTC_Manager_LookupFace(ft_cmanager, (FTC_FaceID)newf, &aface);
diff --git a/frontends/framebuffer/gui.c b/frontends/framebuffer/gui.c
index f0a8f5e58..74768c224 100644
--- a/frontends/framebuffer/gui.c
+++ b/frontends/framebuffer/gui.c
@@ -2214,13 +2214,13 @@ main(int argc, char** argv)
if (ret != NSERROR_OK) {
die("Options failed to initialise");
}
- options = filepath_find(respaths, "Choices");
+ filepath_find(respaths, "Choices", &options);
nsoption_read(options, nsoptions);
free(options);
nsoption_commandline(&argc, argv, nsoptions);

/* message init */
- messages = filepath_find(respaths, "Messages");
+ filepath_find(respaths, "Messages", &messages);
ret = messages_add_from_file(messages);
free(messages);
if (ret != NSERROR_OK) {
diff --git a/frontends/gtk/fetch.c b/frontends/gtk/fetch.c
index d77073a63..36ee36c17 100644
--- a/frontends/gtk/fetch.c
+++ b/frontends/gtk/fetch.c
@@ -257,7 +257,8 @@ static nsurl *nsgtk_get_resource_url(const char *path)
if (strcmp(path, "favicon.ico") == 0) {
nsurl_create("resource:favicon.png", &url);
} else {
- netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url);
+ if (filepath_sfind(respaths, buf, path) == NSERROR_OK)
+ netsurf_path_to_nsurl(buf, &url);
}

return url;
diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c
index 644237e09..fa0c4063b 100644
--- a/frontends/gtk/gui.c
+++ b/frontends/gtk/gui.c
@@ -942,7 +942,7 @@ static nserror nsgtk_setup(int argc, char** argv, char **respath)
}

/* Search engine sources */
- resource_filename = filepath_find(respath, "SearchEngines");
+ filepath_find(respath, "SearchEngines", &resource_filename);
search_web_init(resource_filename);
if (resource_filename != NULL) {
NSLOG(netsurf, INFO, "Using '%s' as Search Engines file",
diff --git a/frontends/gtk/resources.c b/frontends/gtk/resources.c
index fc17f7418..425517b53 100644
--- a/frontends/gtk/resources.c
+++ b/frontends/gtk/resources.c
@@ -246,8 +246,7 @@ init_resource(char **respath, struct nsgtk_resource_s *resource)

No comments:

Post a Comment