summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-06-07 21:55:55 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-06-07 21:55:55 +0200
commit5153780ac2d83cd46113ca1bfd1f7182e748f18e (patch)
treeba48a01ef9b0e647fdd05d525af12925b9f72088 /src
parentf86dcb5ddea5cfb4fa16241318a47428cc2a18a1 (diff)
downloadfeh-5153780ac2d83cd46113ca1bfd1f7182e748f18e.zip
--caption-path: Autocreate caption directories if they don't exist
Diffstat (limited to 'src')
-rw-r--r--src/imlib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/imlib.c b/src/imlib.c
index ae1acb1..1681b38 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -668,7 +668,8 @@ void feh_draw_filename(winwidget w)
char *build_caption_filename(feh_file * file)
{
char *caption_filename;
- char *s, *dir;
+ char *s, *dir, *caption_dir;
+ struct stat cdir_stat;
s = strrchr(file->filename, '/');
if (s) {
dir = estrdup(file->filename);
@@ -677,6 +678,20 @@ char *build_caption_filename(feh_file * file)
} else {
dir = estrdup(".");
}
+
+ caption_dir = estrjoin("/", dir, opt.caption_path, NULL);
+
+ D(4, ("dir %s, cp %s, cdir %s\n", dir, opt.caption_path, caption_dir))
+
+ if (stat(caption_dir, &cdir_stat) == -1) {
+ if (mkdir(caption_dir, 0755) == -1)
+ eprintf("Failed to create caption directory %s:", caption_dir);
+ } else if (!S_ISDIR(cdir_stat.st_mode))
+ eprintf("Caption directory (%s) exists, but is not a directory.",
+ caption_dir);
+
+ free(caption_dir);
+
caption_filename = estrjoin("", dir, "/", opt.caption_path, "/", file->name, ".txt", NULL);
free(dir);
return caption_filename;