aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-04-15 17:43:17 +0200
committerjcid <devnull@localhost>2008-04-15 17:43:17 +0200
commit634f82d108c6ad53e09526f81887d916cca3de12 (patch)
treec57fcb471c9e308c09795c16b1679f45dafb6596 /src/misc.c
parent9c133c549782b93b16769de0ffad1615c34feec5 (diff)
- Made file inputs free the loaded file after the page is left.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/misc.c b/src/misc.c
index c1283380..1b70c1b6 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -269,3 +269,25 @@ char *a_Misc_encode_base64(const char *in)
out[i] = '\0';
return out;
}
+
+/*
+ * Load a local file into a dStr.
+ * Return value: dStr on success, NULL on error.
+ * todo: a filesize threshold may be implemented.
+ */
+Dstr *a_Misc_file2dstr(const char *filename)
+{
+ FILE *F_in;
+ int n;
+ char buf[4096];
+ Dstr *dstr = NULL;
+
+ if ((F_in = fopen(filename, "r"))) {
+ dstr = dStr_sized_new(4096);
+ while ((n = fread (buf, 1, 4096, F_in)) > 0) {
+ dStr_append_l(dstr, buf, n);
+ }
+ fclose(F_in);
+ }
+ return dstr;
+}