bool DirectoryExists(const OsPath& path) { WDIR* dir = wopendir(path); if(dir) { wclosedir(dir); return true; } return false; }
/** Directory tree is now top / topfile middle2 / middle1 / bottom1 / absfile / bottom2 / file -- read-only / read-only / sub-read-only / file @SYMTestCaseID SYSLIB-STDLIB-CT-1050 @SYMTestCaseDesc Tests for enumeration on directories @SYMTestPriority High @SYMTestActions Tests by opening directories @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ void directory() { int err, count, i, j, fd; DIR *dp; struct dirent *ep; char name[MAXPATHLEN+1]; off_t pos; test_Next("Enumerating Directories"); err=chdir(rootpath); test(err==0); dp=opendir("topfile"); /* test_errno(dp==0,ENOTDIR); -- not convinced about this anyway */ test_errno(dp==0,ENOENT); dp=opendir("no such file"); test_errno(dp==0,ENOENT); //test something sensible happens if someone uses a WDIR inplace of a DIR { WDIR *wp = wopendir((wchar_t*)L"."); test(wp!=0); // Test wants a WDIR passed but won't compile under CW. // Force the compile by casting. The function will still get a WDIR. // DIR inherits from WDIR. ep=readdir((DIR*)wp); test_errno(ep==0,EINVAL); wclosedir(wp); } dp=opendir("."); test(dp!=0); count=0; do { ep=readdir(dp); if (ep && strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0) count++; } while (ep!=0); test(count==4); for (i=0; i<4; i++) { rewinddir(dp); for (j=0; j<=i; j++) { ep=readdir(dp); test(ep!=0); } strcpy(name,ep->d_name); rewinddir(dp); for (j=0; j<=i; j++) { ep=readdir(dp); test(ep!=0); } test(strcmp(name,ep->d_name)==0); } for (i=0; i<4; i++) { rewinddir(dp); pos=telldir(dp); for (j=0; j<=i; j++) { pos=telldir(dp); ep=readdir(dp); test(ep!=0); } strcpy(name,ep->d_name); rewinddir(dp); seekdir(dp, pos); ep=readdir(dp); test(ep!=0); test(strcmp(name,ep->d_name)==0); } err=closedir(dp); test(err==0); dp=opendir("middle2"); test(dp!=0); count=0; do { ep=readdir(dp); if (ep && strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0) count++; } while (ep!=0); test(count==0); /* empty directory */ rewinddir(dp); fd = open("middle2/extrafile",O_RDWR+O_CREAT,0777); test(fd>=0); err=close(fd); test(err==0); count=0; do { ep=readdir(dp); if (ep && strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0) count++; } while (ep!=0); test(count==0); /* shouldn't have noticed the change */ rewinddir(dp); /* and spot the new file */ count=0; do { ep=readdir(dp); if (ep && strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0) count++; } while (ep!=0); test(count==1); closedir(dp); dp=opendir("/"); test(dp!=0); count=0; do { ep=readdir(dp); if (ep && strcmp(ep->d_name,".")!=0 && strcmp(ep->d_name,"..")!=0) count++; } while (ep!=0); test(count>0); closedir(dp); }
void operator()(WDIR* osDir) const { const int ret = wclosedir(osDir); ENSURE(ret == 0); }