diff options
Diffstat (limited to 'src/filelist.c')
-rw-r--r-- | src/filelist.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/filelist.c b/src/filelist.c index 361ac19..f1e820c 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -1,7 +1,7 @@ /* filelist.c Copyright (C) 1999-2003 Tom Gilbert. -Copyright (C) 2010-2020 Daniel Friesel. +Copyright (C) 2010-2020 Birte Kristina Friesel. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -24,20 +24,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_LIBEXIF -#include <libexif/exif-data.h> -#endif - #include "feh.h" #include "filelist.h" #include "signals.h" #include "options.h" +#ifdef HAVE_LIBCURL +#include <curl/curl.h> +#endif + gib_list *filelist = NULL; gib_list *original_file_items = NULL; /* original file items from argv */ int filelist_len = 0; gib_list *current_file = NULL; -extern int errno; static gib_list *rm_filelist = NULL; @@ -156,7 +155,7 @@ static void feh_print_stat_error(char *path) } } -static void add_stdin_to_filelist() +static void add_stdin_to_filelist(void) { char buf[1024]; size_t readsize; @@ -181,6 +180,7 @@ static void add_stdin_to_filelist() while ((readsize = fread(buf, sizeof(char), sizeof(buf), stdin)) > 0) { if (fwrite(buf, sizeof(char), readsize, outfile) < readsize) { free(sfn); + fclose(outfile); return; } } @@ -198,7 +198,7 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level) struct stat st; char *path; - if (!origpath) + if (!origpath || *origpath == '\0') return; path = estrdup(origpath); @@ -398,7 +398,7 @@ void feh_file_dirname(char *dst, feh_file * f, int maxlen) return; } - strncpy(dst, f->filename, n); + memcpy(dst, f->filename, n); dst[n] = '\0'; } @@ -641,12 +641,13 @@ char *feh_absolute_path(char *path) filelist file can be saved anywhere and feh will still find the images */ D(("Need to convert %s to an absolute form\n", path)); - /* I SHOULD be able to just use a simple realpath() here, but dumb * + /* I SHOULD be able to just use a simple realpath() here, but dumb * old Solaris's realpath doesn't return an absolute path if the path you give it is relative. Linux and BSD get this right... */ if (getcwd(cwd, sizeof(cwd)) == NULL) eprintf("Cannot determine working directory:"); - snprintf(temp, sizeof(temp), "%s/%s", cwd, path); + if ((size_t) snprintf(temp, sizeof(temp), "%s/%s", cwd, path) >= sizeof(temp)) + eprintf("Absolute path for working directory was truncated"); if (realpath(temp, fullpath) != NULL) { ret = estrdup(fullpath); } else { @@ -656,11 +657,20 @@ char *feh_absolute_path(char *path) return(ret); } -void feh_save_filelist() +void feh_save_filelist(void) { char *tmpname; + char *base_dir = ""; - tmpname = feh_unique_filename("", "filelist"); + if (opt.output_dir) { + base_dir = estrjoin("", opt.output_dir, "/", NULL); + } + + tmpname = feh_unique_filename(base_dir, "filelist"); + + if (opt.output_dir) { + free(base_dir); + } if (opt.verbose) fprintf(stderr, "saving filelist to filename '%s'\n", tmpname); @@ -669,3 +679,27 @@ void feh_save_filelist() free(tmpname); return; } + +#ifdef HAVE_LIBCURL + +char *feh_http_unescape(char *url) +{ + CURL *curl = curl_easy_init(); + if (!curl) { + return NULL; + } + char *tmp_url = curl_easy_unescape(curl, url, 0, NULL); + char *new_url = estrdup(tmp_url); + curl_free(tmp_url); + curl_easy_cleanup(curl); + return new_url; +} + +#else + +char *feh_http_unescape(char *url) +{ + return NULL; +} + +#endif |