summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/feh.h2
-rw-r--r--src/imlib.c13
-rw-r--r--src/keyevents.c5
3 files changed, 13 insertions, 7 deletions
diff --git a/src/feh.h b/src/feh.h
index dc6315f..01006b2 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -143,7 +143,7 @@ void slideshow_save_image(winwidget win);
void feh_edit_inplace_orient(winwidget w, int orientation);
void feh_edit_inplace_lossless_rotate(winwidget w, int orientation);
gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style);
-char *build_caption_filename(feh_file * file);
+char *build_caption_filename(feh_file * file, short create_dir);
gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num);
/* Imlib stuff */
diff --git a/src/imlib.c b/src/imlib.c
index d125286..dcf3c5c 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -505,7 +505,7 @@ void feh_draw_info(winwidget w)
return;
}
-char *build_caption_filename(feh_file * file)
+char *build_caption_filename(feh_file * file, short create_dir)
{
char *caption_filename;
char *s, *dir, *caption_dir;
@@ -524,6 +524,8 @@ char *build_caption_filename(feh_file * file)
D(("dir %s, cp %s, cdir %s\n", dir, opt.caption_path, caption_dir))
if (stat(caption_dir, &cdir_stat) == -1) {
+ if (!create_dir)
+ return NULL;
if (mkdir(caption_dir, 0755) == -1)
eprintf("Failed to create caption directory %s:", caption_dir);
} else if (!S_ISDIR(cdir_stat.st_mode))
@@ -559,9 +561,12 @@ void feh_draw_caption(winwidget w)
if (!file->caption) {
char *caption_filename;
- caption_filename = build_caption_filename(file);
- /* read caption from file */
- file->caption = ereadfile(caption_filename);
+ caption_filename = build_caption_filename(file, 0);
+ if (caption_filename)
+ /* read caption from file */
+ file->caption = ereadfile(caption_filename);
+ else
+ file->caption = estrdup("");
free(caption_filename);
}
diff --git a/src/keyevents.c b/src/keyevents.c
index 896087e..e43ae33 100644
--- a/src/keyevents.c
+++ b/src/keyevents.c
@@ -377,14 +377,15 @@ void feh_event_handle_keypress(XEvent * ev)
/* finish caption entry, write to captions file */
FILE *fp;
char *caption_filename;
- caption_filename = build_caption_filename(FEH_FILE(winwid->file->data));
+ caption_filename =
+ build_caption_filename(FEH_FILE(winwid->file->data), 1);
winwid->caption_entry = 0;
winwidget_render_image_cached(winwid);
XFreePixmap(disp, winwid->bg_pmap_cache);
winwid->bg_pmap_cache = 0;
fp = fopen(caption_filename, "w");
if (!fp) {
- weprintf("couldn't write to captions file %s:", caption_filename);
+ eprintf("couldn't write to captions file %s:", caption_filename);
return;
}
fprintf(fp, "%s", FEH_FILE(winwid->file->data)->caption);