#ifdef _WIN32 // WINDOWS
#define _WIN32_WINNT 0x0501
-#include <Windows.h>
+#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <tchar.h>
if(dirp->d_name[0]!='.'){
DirListNode node;
node.name = dirp->d_name;
- if(dirp->d_type == DT_DIR) node.dir = true;
- else node.dir = false;
- if(node.name != "." && node.name != "..")
- listing.push_back(node);
+ if(node.name == "." || node.name == "..")
+ continue;
+
+ int isdir = -1; // -1 means unknown
+
+ /*
+ POSIX doesn't define d_type member of struct dirent and
+ certain filesystems on glibc/Linux will only return
+ DT_UNKNOWN for the d_type member.
+
+ Also we don't know whether symlinks are directories or not.
+ */
+#ifdef _DIRENT_HAVE_D_TYPE
+ if(dirp->d_type != DT_UNKNOWN && dirp->d_type != DT_LNK)
+ isdir = (dirp->d_type == DT_DIR);
+#endif /* _DIRENT_HAVE_D_TYPE */
+
+ /*
+ Was d_type DT_UNKNOWN, DT_LNK or nonexistent?
+ If so, try stat().
+ */
+ if(isdir == -1)
+ {
+ struct stat statbuf;
+ if (stat((pathstring + "/" + node.name).c_str(), &statbuf))
+ continue;
+ isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
+ }
+ node.dir = isdir;
+ listing.push_back(node);
}
}
closedir(dp);
execv(argv[0], argv);
// Execv shouldn't return. Failed.
- return false;
+ _exit(1);
}
else
{
{
if(trim(list[i].name) == "." || trim(list[i].name) == "..")
continue;
- std::string childpath = path + "/" + list[i].name;
+ std::string childpath = path + DIR_DELIM + list[i].name;
bool r = RecursiveDelete(childpath);
if(r == false)
{
while(!PathExists(basepath))
{
tocreate.push_back(basepath);
- pos = basepath.rfind('/');
+ pos = basepath.rfind(DIR_DELIM_C);
if(pos == std::string::npos)
- return false;
+ break;
basepath = basepath.substr(0,pos);
}
for(int i=tocreate.size()-1;i>=0;i--)
- CreateDir(tocreate[i]);
+ if(!CreateDir(tocreate[i]))
+ return false;
return true;
}