# HG changeset patch # User ib # Date 1301994755 0 # Node ID 4f60cd16ac0449b0c791bb4adef4e4f4ca0b3246 # Parent 5f3171d4d7a41a7919f673826b5f8a7d12c1ef7a Clean up and simplify fExist(). Replace fopen() to check file existence by access(), define variables differently and use FF_ARRAY_ELEMS macro in loop test expression. diff -r 5f3171d4d7a4 -r 4f60cd16ac04 gui/util/bitmap.c --- a/gui/util/bitmap.c Mon Apr 04 19:12:31 2011 +0000 +++ b/gui/util/bitmap.c Tue Apr 05 09:12:35 2011 +0000 @@ -19,6 +19,7 @@ #include #include #include +#include #include "bitmap.h" @@ -160,26 +161,18 @@ static unsigned char *fExist(unsigned char *fname) { - static unsigned char tmp[512]; - FILE *file; - unsigned char ext[][6] = { ".png\0", ".PNG\0" }; - int i; + unsigned char *ext[] = { "png", "PNG" }; + static unsigned char buf[512]; + unsigned int i; - file = fopen(fname, "rb"); - - if (file) { - fclose(file); + if (access(fname, R_OK) == 0) return fname; - } - for (i = 0; i < 2; i++) { - snprintf(tmp, sizeof(tmp), "%s%s", fname, ext[i]); - file = fopen(tmp, "rb"); + for (i = 0; i < FF_ARRAY_ELEMS(ext); i++) { + snprintf(buf, sizeof(buf), "%s.%s", fname, ext[i]); - if (file) { - fclose(file); - return tmp; - } + if (access(buf, R_OK) == 0) + return buf; } return NULL;