Krolyxon
Commit 096c0ed

Branches

Refs →

nsxiv096c0ed

Removed some warnings

Author
Bert
Date
2011-02-03 22:05 +0100
Parent
414fa56
Commit
096c0ed935f7373c15809183ec474f4628d5fa5d

+34 −30

2 files changed

  1. M image.c +1 −1
  2. M main.c +33 −29
M image.c View
@@ -58,7 +58,7 @@ int _imlib_load_image(const char *filename) {
5858 return 0;
5959
6060 if (!(im = imlib_load_image(filename))) {
61− warn("could not open image: %s", filename);
61+ warn("could not open file: %s", filename);
6262 return 0;
6363 }
6464
M main.c View
@@ -33,7 +33,7 @@
3333 #include "window.h"
3434
3535 void update_title();
36−void check_append(const char*);
36+int check_append(const char*);
3737 void read_dir_rec(const char*);
3838 void run();
3939
@@ -61,10 +61,10 @@ void cleanup() {
6161 int load_image() {
6262 struct stat fstats;
6363
64− if (stat(filenames[fileidx], &fstats))
65− warn("could not stat file: %s", filenames[fileidx]);
66− else
64+ if (!stat(filenames[fileidx], &fstats))
6765 filesize = fstats.st_size;
66+ else
67+ filesize = 0;
6868
6969 return img_load(&img, filenames[fileidx]);
7070 }
@@ -91,9 +91,7 @@ int main(int argc, char **argv) {
9191
9292 for (i = 0; i < options->filecnt; ++i) {
9393 filename = options->filenames[i];
94− if (stat(filename, &fstats)) {
95− warn("could not stat file: %s", filename);
96− } else if (S_ISDIR(fstats.st_mode)) {
94+ if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) {
9795 if (options->recursive)
9896 read_dir_rec(filename);
9997 else
@@ -145,9 +143,9 @@ void update_title() {
145143 win_set_title(&win, win_title);
146144 }
147145
148−void check_append(const char *filename) {
146+int check_append(const char *filename) {
149147 if (!filename)
150− return;
148+ return 0;
151149
152150 if (img_check(filename)) {
153151 if (fileidx == filecnt) {
@@ -156,6 +154,9 @@ void check_append(const char *filename) {
156154 filecnt * sizeof(const char*));
157155 }
158156 filenames[fileidx++] = filename;
157+ return 1;
158+ } else {
159+ return 0;
159160 }
160161 }
161162
@@ -179,29 +180,32 @@ void read_dir_rec(const char *dirname) {
179180
180181 while (diridx > 0) {
181182 dirname = dirnames[--diridx];
182− if (!(dir = opendir(dirname)))
183− die("could not open directory: %s", dirname);
184− while ((dentry = readdir(dir))) {
185− if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
186− continue;
187− len = strlen(dirname) + strlen(dentry->d_name) + 2;
188− filename = (char*) s_malloc(len * sizeof(char));
189− snprintf(filename, len, "%s/%s", dirname, dentry->d_name);
190− if (stat(filename, &fstats)) {
191− warn("could not stat file: %s", filename);
192− free(filename);
193− } else if (S_ISDIR(fstats.st_mode)) {
194− if (diridx == dircnt) {
195− dircnt *= 2;
196− dirnames = (const char**) s_realloc(dirnames,
197− dircnt * sizeof(const char*));
183+ if (!(dir = opendir(dirname))) {
184+ warn("could not open directory: %s", dirname);
185+ } else {
186+ while ((dentry = readdir(dir))) {
187+ if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
188+ continue;
189+
190+ len = strlen(dirname) + strlen(dentry->d_name) + 2;
191+ filename = (char*) s_malloc(len * sizeof(char));
192+ snprintf(filename, len, "%s/%s", dirname, dentry->d_name);
193+
194+ if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) {
195+ if (diridx == dircnt) {
196+ dircnt *= 2;
197+ dirnames = (const char**) s_realloc(dirnames,
198+ dircnt * sizeof(const char*));
199+ }
200+ dirnames[diridx++] = filename;
201+ } else {
202+ if (!check_append(filename))
203+ free(filename);
198204 }
199− dirnames[diridx++] = filename;
200− } else {
201− check_append(filename);
202205 }
206+ closedir(dir);
203207 }
204− closedir(dir);
208+
205209 if (!first)
206210 free((void*) dirname);
207211 else