diff options
author | jcid <devnull@localhost> | 2008-04-15 17:43:17 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-04-15 17:43:17 +0200 |
commit | 634f82d108c6ad53e09526f81887d916cca3de12 (patch) | |
tree | c57fcb471c9e308c09795c16b1679f45dafb6596 /src/misc.c | |
parent | 9c133c549782b93b16769de0ffad1615c34feec5 (diff) |
- Made file inputs free the loaded file after the page is left.
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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; +} |