From 0084d755618c8a5a55f36bbdd2c17952dfae68f0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 8 Feb 2013 18:04:21 +0100 Subject: handle stdin when loading filelist so it also works with --list, rotation, etc. --- src/filelist.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/filelist.c') 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) { -- cgit v1.2.3