diff options
author | Daniel Friesel <derf@finalrewind.org> | 2013-02-08 18:04:21 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2013-02-08 18:04:21 +0100 |
commit | 0084d755618c8a5a55f36bbdd2c17952dfae68f0 (patch) | |
tree | 1ae5d91a86752c17b03bdd70692f5e52abdb282b /src/filelist.c | |
parent | 6ea43a3213bb264525e04c729c67204f82c7a2c8 (diff) |
handle stdin when loading filelist so it also works with --list, rotation, etc.
Diffstat (limited to 'src/filelist.c')
-rw-r--r-- | src/filelist.c | 38 |
1 files changed, 36 insertions, 2 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) { |