<div dir="ltr"><div><div><div><div><div><div><div><div>While I was messing around trying to figure out what was going on during my kernel error crisis, I noticed the current implementation of the isdir() function:<br><br>FUNCTION isdir (sDir as string) as integer<br>  dim ret as bool<br>#IFDEF __FB_ANDROID__<br>  '[ does not work in Android 2.2. I don't know how reliable this is<br>  ret = SHELL("ls " + escape_filename(sDir) + "/") = 0<br>#ELSEIF DEFINED(__UNIX__)<br>  'Special hack for broken Linux dir() behavior<br>  '(FIXME: is DIR still broken? Should investigate)<br>  ret = SHELL("[ -d " + escape_filename(sDir) + " ]") = 0<br>#ELSE<br>  'Windows just uses dir (ugh)<br>  'Have to remove trailing slash, otherwise dir always returns nothing<br>  dim temp as string = rtrim(sdir, any "\/")<br>  ret = dir(temp, 55) <> "" AND dir(temp, 39) = ""<br>#ENDIF<br>#IFDEF DEBUG_FILE_IO<br>  debuginfo "isdir(" & sDir & ") = " & ret<br>#ENDIF<br>  return ret<br>END FUNCTION<br><br></div>It has three different platform specific code-paths, and all of them seem pretty dang hacky.<br><br></div>I realized that a C implementation of the same function would probably be relatively simple, and might even be the same across all four supported platforms.<br><br></div>After googling around a bit, I came up with something, but my C legs are pretty shakey, so I was hoping somebody else could look at it before I go and further along this path, especially if this implementation does something dumb that I am missing or would not work on one of our platforms<br><br>int isdir(const char *dirname)<br>{<br>       struct stat sb;<br><br>       if (stat(dirname, &sb) == 0 && S_ISDIR(sb.st_mode)) {<br>               return 1;<br>       }<br>       return 0;<br>}<br><br></div>I am also unsure which c source file is the right place to put this. Is miscc.c the right place?<br><br></div>It requires:<br><br>#include <sys/stat.h>
<br>#include <stdio.h>
<br><br></div>neither of which is currently included in miscc.c right now, and I have no idea if sys.stat.h is a unix-only thing or not.<br><br></div>---<br></div>James<br><br></div>