Removed some warnings

This commit is contained in:
Bert 2011-02-03 22:05:13 +01:00
parent 414fa567ce
commit 096c0ed935
2 changed files with 34 additions and 30 deletions

View File

@ -58,7 +58,7 @@ int _imlib_load_image(const char *filename) {
return 0; return 0;
if (!(im = imlib_load_image(filename))) { if (!(im = imlib_load_image(filename))) {
warn("could not open image: %s", filename); warn("could not open file: %s", filename);
return 0; return 0;
} }

62
main.c
View File

@ -33,7 +33,7 @@
#include "window.h" #include "window.h"
void update_title(); void update_title();
void check_append(const char*); int check_append(const char*);
void read_dir_rec(const char*); void read_dir_rec(const char*);
void run(); void run();
@ -61,10 +61,10 @@ void cleanup() {
int load_image() { int load_image() {
struct stat fstats; struct stat fstats;
if (stat(filenames[fileidx], &fstats)) if (!stat(filenames[fileidx], &fstats))
warn("could not stat file: %s", filenames[fileidx]);
else
filesize = fstats.st_size; filesize = fstats.st_size;
else
filesize = 0;
return img_load(&img, filenames[fileidx]); return img_load(&img, filenames[fileidx]);
} }
@ -91,9 +91,7 @@ int main(int argc, char **argv) {
for (i = 0; i < options->filecnt; ++i) { for (i = 0; i < options->filecnt; ++i) {
filename = options->filenames[i]; filename = options->filenames[i];
if (stat(filename, &fstats)) { if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) {
warn("could not stat file: %s", filename);
} else if (S_ISDIR(fstats.st_mode)) {
if (options->recursive) if (options->recursive)
read_dir_rec(filename); read_dir_rec(filename);
else else
@ -145,9 +143,9 @@ void update_title() {
win_set_title(&win, win_title); win_set_title(&win, win_title);
} }
void check_append(const char *filename) { int check_append(const char *filename) {
if (!filename) if (!filename)
return; return 0;
if (img_check(filename)) { if (img_check(filename)) {
if (fileidx == filecnt) { if (fileidx == filecnt) {
@ -156,6 +154,9 @@ void check_append(const char *filename) {
filecnt * sizeof(const char*)); filecnt * sizeof(const char*));
} }
filenames[fileidx++] = filename; filenames[fileidx++] = filename;
return 1;
} else {
return 0;
} }
} }
@ -179,29 +180,32 @@ void read_dir_rec(const char *dirname) {
while (diridx > 0) { while (diridx > 0) {
dirname = dirnames[--diridx]; dirname = dirnames[--diridx];
if (!(dir = opendir(dirname))) if (!(dir = opendir(dirname))) {
die("could not open directory: %s", dirname); warn("could not open directory: %s", dirname);
while ((dentry = readdir(dir))) { } else {
if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) while ((dentry = readdir(dir))) {
continue; if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, ".."))
len = strlen(dirname) + strlen(dentry->d_name) + 2; continue;
filename = (char*) s_malloc(len * sizeof(char));
snprintf(filename, len, "%s/%s", dirname, dentry->d_name); len = strlen(dirname) + strlen(dentry->d_name) + 2;
if (stat(filename, &fstats)) { filename = (char*) s_malloc(len * sizeof(char));
warn("could not stat file: %s", filename); snprintf(filename, len, "%s/%s", dirname, dentry->d_name);
free(filename);
} else if (S_ISDIR(fstats.st_mode)) { if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) {
if (diridx == dircnt) { if (diridx == dircnt) {
dircnt *= 2; dircnt *= 2;
dirnames = (const char**) s_realloc(dirnames, dirnames = (const char**) s_realloc(dirnames,
dircnt * sizeof(const char*)); dircnt * sizeof(const char*));
}
dirnames[diridx++] = filename;
} else {
if (!check_append(filename))
free(filename);
} }
dirnames[diridx++] = filename;
} else {
check_append(filename);
} }
closedir(dir);
} }
closedir(dir);
if (!first) if (!first)
free((void*) dirname); free((void*) dirname);
else else