diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/filelist.c | 38 | ||||
-rw-r--r-- | src/imlib.c | 39 |
2 files changed, 37 insertions, 40 deletions
diff --git a/src/filelist.c b/src/filelist.c index 3ea0928..0aafa64 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -155,6 +155,40 @@ static void feh_print_stat_error(char *path) } } +static void add_stdin_to_filelist() +{ + char buf[1024]; + size_t readsize; + char *sfn = estrjoin("_", "/tmp/feh_stdin", "XXXXXX", NULL); + int fd = mkstemp(sfn); + FILE *outfile; + + if (fd == -1) { + free(sfn); + weprintf("cannot read from stdin: mktemp:"); + return; + } + + outfile = fdopen(fd, "w"); + + if (outfile == NULL) { + free(sfn); + weprintf("cannot read from stdin: fdopen:"); + return; + } + + while ((readsize = fread(buf, sizeof(char), sizeof(buf), stdin)) > 0) { + if (fwrite(buf, sizeof(char), readsize, outfile) < readsize) { + free(sfn); + return; + } + } + fclose(outfile); + + filelist = gib_list_add_front(filelist, feh_file_new(sfn)); + free(sfn); +} + /* Recursive */ void add_file_to_filelist_recursively(char *origpath, unsigned char level) @@ -186,8 +220,8 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level) free(path); return; } else if ((len == 1) && (path[0] == '-')) { - D(("Addig stdin (-) to filelist\n")); - filelist = gib_list_add_front(filelist, feh_file_new(path)); + D(("Adding temporary file for stdin (-) to filelist\n")); + add_stdin_to_filelist(); free(path); return; } else if (opt.filelistfile) { diff --git a/src/imlib.c b/src/imlib.c index bdf54ac..98a91be 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -61,7 +61,6 @@ int num_xinerama_screens; int childpid = 0; -static char *feh_stdin_load_image(); static char *feh_http_load_image(char *url); static char *feh_magick_load_image(char *filename); @@ -210,7 +209,7 @@ void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err) int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err; - enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK, SRC_STDIN } image_source = + enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source = SRC_IMLIB; char *tmpname = NULL; char *real_filename = NULL; @@ -227,10 +226,6 @@ int feh_load_image(Imlib_Image * im, feh_file * file) tmpname = feh_http_load_image(file->filename); } - if ((strlen(file->filename) == 1) && (file->filename[0] == '-')) { - image_source = SRC_STDIN; - tmpname = feh_stdin_load_image(); - } else *im = imlib_load_image_with_error_return(file->filename, &err); @@ -275,38 +270,6 @@ int feh_load_image(Imlib_Image * im, feh_file * file) return(1); } -static char *feh_stdin_load_image() -{ - char buf[1024]; - size_t readsize; - char *sfn = estrjoin("_", "/tmp/feh_stdin", "XXXXXX", NULL); - int fd = mkstemp(sfn); - FILE *outfile; - - if (fd == -1) { - free(sfn); - return NULL; - } - - outfile = fdopen(fd, "w"); - - if (outfile == NULL) { - free(sfn); - return NULL; - } - - while ((readsize = fread(buf, sizeof(char), sizeof(buf), stdin)) > 0) { - if (fwrite(buf, sizeof(char), readsize, outfile) < readsize) { - free(sfn); - return NULL; - } - } - - fclose(outfile); - - return sfn; -} - static char *feh_magick_load_image(char *filename) { char argv_fd[12]; |