- if( ! strchr(mode, 'r') )
- return fopen(path, mode);
-
- if ( (stat(path, &s)) == -1 )
- return NULL;
-
- return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL;
+ stat_ok = (stat(path, &s) != -1);
+
+ if(strchr(mode, 'r'))
+ return (stat_ok && S_ISREG(s.st_mode)) ?
+ fopen(path, mode) : NULL;
+ else
+ return (stat_ok && S_ISDIR(s.st_mode)) ?
+ NULL : fopen(path, mode);