Krolyxon
Commit 426edfb

Branches

Refs →

nsxiv426edfb

Readded file-type check at startup

Author
Bert
Date
2011-04-05 00:37 +0200
Parent
8d4e3a5
Commit
426edfb3498469b171aae6a582491c2c7e30fd51

+27 −5

3 files changed

  1. M Makefile +1 −1
  2. M image.c +18 −1
  3. M main.c +8 −3
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110404
3+VERSION=git-20110405
44
55 CC?=gcc
66 PREFIX?=/usr/local
M image.c View
@@ -56,6 +56,23 @@ void img_free(img_t* img) {
5656 imlib_free_image();
5757 }
5858
59+int img_check(const char *filename) {
60+ Imlib_Image *im;
61+
62+ if (!filename)
63+ return 0;
64+
65+ if ((im = imlib_load_image(filename))) {
66+ imlib_context_set_image(im);
67+ imlib_image_set_changes_on_disk();
68+ imlib_free_image();
69+ return 1;
70+ } else {
71+ warn("invalid file: %s", filename);
72+ return 0;
73+ }
74+}
75+
5976 int img_load(img_t *img, const char *filename) {
6077 if (!img || !filename)
6178 return 0;
@@ -66,7 +83,7 @@ int img_load(img_t *img, const char *filename) {
6683 imlib_context_set_anti_alias(img->aa);
6784 img->scalemode = options->scalemode;
6885 } else {
69− warn("not an image: %s", filename);
86+ warn("invalid file: %s", filename);
7087 imlib_context_set_image(im_invalid);
7188 imlib_context_set_anti_alias(0);
7289 }
M main.c View
@@ -178,7 +178,7 @@ void update_title() {
178178 fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
179179 filenames[fileidx]);
180180 } else {
181− n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] not an image: %s",
181+ n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] invalid: %s",
182182 fileidx + 1, filecnt, filenames[fileidx]);
183183 }
184184 }
@@ -193,7 +193,13 @@ void update_title() {
193193 }
194194
195195 int check_append(const char *filename) {
196− if (filename && !access(filename, R_OK)) {
196+ if (!filename)
197+ return 0;
198+
199+ if (access(filename, R_OK)) {
200+ warn("could not open file: %s", filename);
201+ return 0;
202+ } else if (img_check(filename)) {
197203 if (fileidx == filecnt) {
198204 filecnt *= 2;
199205 filenames = (const char**) s_realloc(filenames,
@@ -202,7 +208,6 @@ int check_append(const char *filename) {
202208 filenames[fileidx++] = filename;
203209 return 1;
204210 } else {
205− warn("could not open file: %s", filename);
206211 return 0;
207212 }
208213 }