summaryrefslogtreecommitdiff
path: root/framebuffer/findfile.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2009-06-28 18:32:47 +0000
committerVincent Sanders <vince@netsurf-browser.org>2009-06-28 18:32:47 +0000
commit36b5deef09d0390e6d1a7bac9362bb8bc0008b0b (patch)
tree6651d5abb5ee71da281481acce7fcc36b3bae00c /framebuffer/findfile.c
parentd570a80b59361ebfb8ef9ba4e64f1f74bff18855 (diff)
downloadnetsurf-36b5deef09d0390e6d1a7bac9362bb8bc0008b0b.tar.gz
netsurf-36b5deef09d0390e6d1a7bac9362bb8bc0008b0b.tar.bz2
Make framebuffer port use libnsfb
svn path=/trunk/netsurf/; revision=8122
Diffstat (limited to 'framebuffer/findfile.c')
-rw-r--r--framebuffer/findfile.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c
new file mode 100644
index 000000000..29b82588d
--- /dev/null
+++ b/framebuffer/findfile.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2008 Daniel Silverstone <dsilvers@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <limits.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils/log.h"
+
+#include "framebuffer/findfile.h"
+
+char *path_to_url(const char *path)
+{
+ char *r = malloc(strlen(path) + 7 + 1);
+
+ strcpy(r, "file://");
+ strcat(r, path);
+
+ return r;
+}
+
+/**
+ * Locate a shared resource file by searching known places in order.
+ *
+ * \param buf buffer to write to. must be at least PATH_MAX chars
+ * \param filename file to look for
+ * \param def default to return if file not found
+ * \return buf
+ *
+ * Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an
+ * environment variable), and finally the path specified by NETSURF_FB_RESPATH
+ * from the Makefile
+ */
+
+char *fb_find_resource(char *buf, const char *filename, const char *def)
+{
+ char *cdir = getenv("HOME");
+ char t[PATH_MAX];
+
+ if (cdir != NULL) {
+ strcpy(t, cdir);
+ strcat(t, "/.netsurf/");
+ strcat(t, filename);
+ if (realpath(t, buf) != NULL) {
+ if (access(buf, R_OK) == 0)
+ return buf;
+ }
+ }
+
+ cdir = getenv("NETSURFRES");
+
+ if (cdir != NULL) {
+ if (realpath(cdir, buf) != NULL) {
+ strcat(buf, "/");
+ strcat(buf, filename);
+ if (access(buf, R_OK) == 0)
+ return buf;
+ }
+ }
+
+ strcpy(t, NETSURF_FB_RESPATH);
+ strcat(t, filename);
+ if (realpath(t, buf) != NULL) {
+ if (access(buf, R_OK) == 0)
+ return buf;
+ }
+
+ if (def[0] == '~') {
+ snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1);
+ if (realpath(t, buf) == NULL) {
+ strcpy(buf, t);
+ }
+ } else {
+ if (realpath(def, buf) == NULL) {
+ strcpy(buf, def);
+ }
+ }
+
+ return buf;
+}
+
+
+/*
+ * Local Variables:
+ * c-basic-offset: 8
+ * End:
+ */
+