static int dirWalk(const char * dn) { rpmop op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); int xx = rpmswEnter(op, 0); DIR * dir; struct dirent * dp; off_t d_off = -1; int nentries = 0; int rc = 1; if ((dir = Opendir(dn)) == NULL) goto exit; while ((dp = Readdir(dir)) != NULL) { if (nentries == 0) d_off = Telldir(dir); printDir(dp, Telldir(dir), nentries++); } #ifdef NOISY nentries = 0; Rewinddir(dir); while ((dp = Readdir(dir)) != NULL) printDir(dp, Telldir(dir), nentries++); Seekdir(dir, d_off); while ((dp = Readdir(dir)) != NULL) { printDir(dp, Telldir(dir), 0); break; } #endif rc = Closedir(dir); #ifdef REFERENCE { struct dirent ** dirents = NULL; int i; nentries = Scandir(dn, &dirents, NULL, Alphasort); for (i = 0; i < nentries; i++) { dp = dirents[i]; printDir(dp, dp->d_off, i); dirents[i] = _free(dirents[i]); } dirents = _free(dirents); } #endif exit: xx = rpmswExit(op, nentries); fprintf(stderr, "===== %s: %d entries\n", dn, nentries); if (_rpmsw_stats) rpmswPrint("opendir:", op, NULL); return rc; }
int ReportGenerateFolder(Report *self, const char *cszDirPath) { int rc, state, iLenPath, iLenRest; DIR *dir; char szPathReport[BUF_SIZE_MID + 1]; struct dirent *entry; rc = 0; try { #if defined(_WIN32) #elif defined(__linux__) dir = NULL; state = Mkdir(cszDirPath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); /* The folder already exists and we should remove all the files in it. */ if (state != 0) { dir = Opendir(cszDirPath); iLenPath = strlen(cszDirPath); memset(szPathReport, 0, sizeof(char) * (BUF_SIZE_MID + 1)); strcpy(szPathReport, cszDirPath); if (cszDirPath[iLenPath - 1] != OS_PATH_SEPARATOR) { szPathReport[iLenPath] = OS_PATH_SEPARATOR; iLenPath++; } while ((entry = Readdir(dir)) != NULL) { if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) continue; strcpy(szPathReport + iLenPath, entry->d_name); Unlink(szPathReport); iLenRest = strlen(entry->d_name); memset(szPathReport + iLenPath, 0, sizeof(char) * iLenRest); } } #endif } catch(EXCEPT_IO_DIR_MAKE) { rc = -1; } catch(EXCEPT_IO_DIR_OPEN) { rc = -1; } catch(EXCEPT_IO_DIR_READ) { rc = -1; } catch(EXCEPT_IO_FILE_UNLINK) { rc = -1; } end_try; if (dir != NULL) Closedir(dir); EXIT: return rc; }
void globdir(uint8_t *p, uint8_t *namep) { uint8_t *t, *newp; int f; /* scan the pattern looking for a component with a metacharacter in it */ if(*p=='\0'){ globv = newword(globname, globv); return; } t = namep; newp = p; while(*newp){ if(*newp==GLOB) break; *t=*newp++; if(*t++=='/'){ namep = t; p = newp; } } /* If we ran out of pattern, append the name if accessible */ if(*newp=='\0'){ *t='\0'; if(access(globname, 0)==0) globv = newword(globname, globv); return; } /* read the directory and recur for any entry that matches */ *namep='\0'; if((f = Opendir(globname[0]?globname:"."))<0) return; while(*newp!='/' && *newp!='\0') newp++; while(Readdir(f, namep, *newp=='/')){ if(matchfn(namep, p)){ for(t = namep;*t;t++); globdir(newp, t); } } Closedir(f); }
/* --- Object ctors/dtors */ static DIR * rpmdir_init(JSContext *cx, JSObject *obj, const char * _dn) { DIR * dir = NULL; if (_dn) { dir = Opendir(_dn); /* XXX error msg */ if (!JS_SetPrivate(cx, obj, (void *)dir)) { /* XXX error msg */ if (dir) { (void) Closedir(dir); /* XXX error msg */ } dir = NULL; } } if (_debug) fprintf(stderr, "<== %s(%p,%p,\"%s\") dir %p\n", __FUNCTION__, cx, obj, _dn, dir); return dir; }
int main(int argc, char **argv) { DIR *streamp; struct dirent *dep; /* $end readdir */ if (argc != 2) { printf("usage: %s <pathname>\n", argv[0]); exit(1); } /* $begin readdir */ streamp = Opendir(argv[1]); errno = 0; while ((dep = readdir(streamp)) != NULL) { printf("Found file: %s\n", dep->d_name); } if (errno != 0) unix_error("readdir error"); Closedir(streamp); exit(0); }
static int glob3(struct strbuf *pathbuf, const Char *pattern, const Char *restpattern, const Char *pglobstar, glob_t *pglob, int no_match) { DIR *dirp; struct dirent *dp; struct stat sbuf; int err; Char m_not = (pglob->gl_flags & GLOB_ALTNOT) ? M_ALTNOT : M_NOT; size_t orig_len; int globstar = 0; int chase_symlinks = 0; const Char *termstar = NULL; strbuf_terminate(pathbuf); orig_len = pathbuf->len; errno = err = 0; while (pglobstar < restpattern) { __Char wc; size_t width = One_Char_mbtowc(&wc, pglobstar, MB_LEN_MAX); if ((pglobstar[0] & M_MASK) == M_ALL && (pglobstar[width] & M_MASK) == M_ALL) { globstar = 1; chase_symlinks = (pglobstar[2 * width] & M_MASK) == M_ALL; termstar = pglobstar + (2 + chase_symlinks) * width; break; } pglobstar += width; } if (globstar) { err = pglobstar==pattern && termstar==restpattern ? *restpattern == EOS ? glob2(pathbuf, restpattern - 1, pglob, no_match) : glob2(pathbuf, restpattern + 1, pglob, no_match) : glob3(pathbuf, pattern, restpattern, termstar, pglob, no_match); if (err) return err; pathbuf->len = orig_len; strbuf_terminate(pathbuf); } if (*pathbuf->s && (Lstat(pathbuf->s, &sbuf) || !S_ISDIR(sbuf.st_mode) #ifdef S_IFLINK && ((globstar && !chase_symlinks) || !S_ISLNK(sbuf.st_mode)) #endif )) return 0; if (!(dirp = Opendir(pathbuf->s))) { /* todo: don't call for ENOENT or ENOTDIR? */ if ((pglob->gl_errfunc && (*pglob->gl_errfunc) (pathbuf->s, errno)) || (pglob->gl_flags & GLOB_ERR)) return (GLOB_ABEND); else return (0); } /* search directory for matching names */ while ((dp = readdir(dirp)) != NULL) { /* initial DOT must be matched literally */ if (dp->d_name[0] == DOT && *pattern != DOT) if (!(pglob->gl_flags & GLOB_DOT) || !dp->d_name[1] || (dp->d_name[1] == DOT && !dp->d_name[2])) continue; /*unless globdot and not . or .. */ pathbuf->len = orig_len; strbuf_append(pathbuf, dp->d_name); strbuf_terminate(pathbuf); if (globstar) { #ifdef S_IFLNK if (!chase_symlinks && (Lstat(pathbuf->s, &sbuf) || S_ISLNK(sbuf.st_mode))) continue; #endif if (match(pathbuf->s + orig_len, pattern, termstar, (int)m_not) == no_match) continue; strbuf_append1(pathbuf, SEP); strbuf_terminate(pathbuf); if ((err = glob2(pathbuf, pglobstar, pglob, no_match)) != 0) break; } else { if (match(pathbuf->s + orig_len, pattern, restpattern, (int) m_not) == no_match) continue; if ((err = glob2(pathbuf, restpattern, pglob, no_match)) != 0) break; } } /* todo: check error from readdir? */ closedir(dirp); return (err); }
TVerdict CTestSyscalls::doTestStepL() { int err; if(TestStepName() == KCreat) { INFO_PRINTF1(_L("Creat():")); err = Creat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen1) { INFO_PRINTF1(_L("open1():")); err = open1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen2) { INFO_PRINTF1(_L("open2():")); err = open2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen3) { INFO_PRINTF1(_L("open3():")); err = open3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen4) { INFO_PRINTF1(_L("open4():")); err = open4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen5) { INFO_PRINTF1(_L("open5():")); err = open5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen6) { INFO_PRINTF1(_L("open6():")); err = open6(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate1) { INFO_PRINTF1(_L("OpenTruncate1:")); err = OpenTruncate1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate2) { INFO_PRINTF1(_L("OpenTruncate2:")); err = OpenTruncate2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen7) { INFO_PRINTF1(_L("open7():")); err = open7(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenInAppendMode) { INFO_PRINTF1(_L("OpenInAppendMode():")); err = OpenInAppendMode(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite1) { INFO_PRINTF1(_L("write1():")); err = write1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite2) { INFO_PRINTF1(_L("write2():")); err = write2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite3) { INFO_PRINTF1(_L("write3():")); err = write3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite5) { INFO_PRINTF1(_L("write5():")); err = write5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread1) { INFO_PRINTF1(_L("read1():")); err = read1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread2) { INFO_PRINTF1(_L("read2():")); err = read2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread3) { INFO_PRINTF1(_L("read3():")); err = read3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread4) { INFO_PRINTF1(_L("read4():")); err = read4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpendir) { INFO_PRINTF1(_L("Opendir():")); err = Opendir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClosedir) { INFO_PRINTF1(_L("Closedir():")); err = Closedir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReaddir) { INFO_PRINTF1(_L("Readdir():")); err = Readdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek) { INFO_PRINTF1(_L("Lseek():")); err = Lseek(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek1) { INFO_PRINTF1(_L("Lseek1():")); err = Lseek1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess) { INFO_PRINTF1(_L("Access():")); err = Access(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess1) { INFO_PRINTF1(_L("Access1():")); err = Access1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup) { INFO_PRINTF1(_L("Dup():")); err = Dup(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup2) { INFO_PRINTF1(_L("Dup2():")); err = Dup2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename) { INFO_PRINTF1(_L("Rename():")); err = Rename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename1) { INFO_PRINTF1(_L("Rename1():")); err = Rename1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod) { INFO_PRINTF1(_L("Chmod():")); err = Chmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod1) { INFO_PRINTF1(_L("Chmod1():")); err = Chmod1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_dir) { INFO_PRINTF1(_L("Chmod_dir():")); err = Chmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod) { INFO_PRINTF1(_L("FChmod():")); err = FChmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod_dir) { INFO_PRINTF1(_L("FChmod_dir():")); err = FChmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KExit) { INFO_PRINTF1(_L("Exit():")); err = Exit(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClose) { INFO_PRINTF1(_L("Close():")); err = Close(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir) { INFO_PRINTF1(_L("Mkdir():")); err = Mkdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMk_dir) { INFO_PRINTF1(_L("Mk_dir():")); err = Mk_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir) { INFO_PRINTF1(_L("Rmdir():")); err = Rmdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRm_dir) { INFO_PRINTF1(_L("Rm_dir():")); err = Rm_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir1) { INFO_PRINTF1(_L("Rmdir1():")); err = Rmdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir_Chdir) { INFO_PRINTF1(_L("Rmdir_Chdir():")); err = Rmdir_Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFsync) { INFO_PRINTF1(_L("Fsync():")); err = Fsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes) { INFO_PRINTF1(_L("Utimes():")); err = Utimes(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtime) { INFO_PRINTF1(_L("Utime():")); err = Utime(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir) { INFO_PRINTF1(_L("Chdir():")); err = Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFcntl) { INFO_PRINTF1(_L("Fcntl():")); err = Fcntl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KIoctl) { INFO_PRINTF1(_L("Ioctl():")); err = Ioctl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat) { INFO_PRINTF1(_L("Fstat():")); err = Fstat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat) { INFO_PRINTF1(_L("Stat():")); err = Stat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat1) { INFO_PRINTF1(_L("Stat1():")); err = Stat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat2) { INFO_PRINTF1(_L("Stat2():")); err = Stat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat3) { INFO_PRINTF1(_L("Stat3():")); err = Stat3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KGetpid) { INFO_PRINTF1(_L("Getpid():")); err = Getpid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClock) { INFO_PRINTF1(_L("Clock():")); err = Clock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTime) { INFO_PRINTF1(_L("Time():")); err = Time(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPid) { INFO_PRINTF1(_L("WaitPid():")); err = WaitPid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV) { INFO_PRINTF1(_L("ReadV():")); err = ReadV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWriteV) { INFO_PRINTF1(_L("WriteV():")); err = WriteV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSleep) { INFO_PRINTF1(_L("Sleep():")); err = Sleep(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSeekDir) { INFO_PRINTF1(_L("SeekDir():")); err = SeekDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRewindDir) { INFO_PRINTF1(_L("RewindDir():")); err = RewindDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTelldir) { INFO_PRINTF1(_L("Telldir():")); err = Telldir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestClock) { INFO_PRINTF1(_L("TestClock():")); err = TestClock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat2) { INFO_PRINTF1(_L("Creat2():")); err = Creat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen8) { INFO_PRINTF1(_L("open8():")); err = open8(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestStat) { INFO_PRINTF1(_L("KTestStat():")); err = TestStat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest1) { INFO_PRINTF1(_L("Lseekttytest1():")); err = Lseekttytest1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest2) { INFO_PRINTF1(_L("Lseekttytest2():")); err = Lseekttytest2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPidtest) { INFO_PRINTF1(_L("WaitPidtest():")); err = WaitPidtest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaittest) { INFO_PRINTF1(_L("Waittest():")); err = Waittest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpen_FileDes_Test) { INFO_PRINTF1(_L("Open_FileDes_Test():")); err = Open_FileDes_Test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopenuid) { INFO_PRINTF1(_L("openuid():")); err = openuid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir1) { INFO_PRINTF1(_L("Mkdir1():")); err = Mkdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir2) { INFO_PRINTF1(_L("Mkdir2():")); err = Mkdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename2) { INFO_PRINTF1(_L("Rename2():")); err = Rename2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestfsync) { INFO_PRINTF1(_L("testfsync():")); err = testfsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestrename) { INFO_PRINTF1(_L("testrename():")); err = testrename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestopenvalidate) { INFO_PRINTF1(_L("testopenvalidate():")); err = testopenvalidate(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ksync_safe) { INFO_PRINTF1(_L("sync_safe():")); err = sync_safe(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat1) { INFO_PRINTF1(_L("Fstat1():")); err = Fstat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes1) { INFO_PRINTF1(_L("Utimes1():")); err = Utimes1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test1) { INFO_PRINTF1(_L("Mkdir_test1():")); err = Mkdir_test1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_test) { INFO_PRINTF1(_L("Chmod_test():")); err = Chmod_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir1) { INFO_PRINTF1(_L("Chdir1():")); err = Chdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir2) { INFO_PRINTF1(_L("Rmdir2():")); err = Rmdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename_test) { INFO_PRINTF1(_L("Rename_test():")); err = Rename_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename3) { INFO_PRINTF1(_L("Rename3():")); err = Rename3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat1) { INFO_PRINTF1(_L("Creat1():")); err = Creat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV1) { INFO_PRINTF1(_L("ReadV1():")); err = ReadV1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes2) { INFO_PRINTF1(_L("Utimes2():")); err = Utimes2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat_test) { INFO_PRINTF1(_L("Stat_test():")); err = Stat_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test2) { INFO_PRINTF1(_L("Mkdir_test2():")); err = Mkdir_test2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod2) { INFO_PRINTF1(_L("Chmod2():")); err = Chmod2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir2) { INFO_PRINTF1(_L("Chdir2():")); err = Chdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename4) { INFO_PRINTF1(_L("Rename4():")); err = Rename4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename5) { INFO_PRINTF1(_L("Rename5():")); err = Rename5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir3) { INFO_PRINTF1(_L("Rmdir3():")); err = Rmdir3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread5) { INFO_PRINTF1(_L("read5():")); err = read5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } return TestStepResult(); }
static void do_FEF( Fchar *fn, void (*proc)(const Fchar *, const char *, const struct stat *), int dev, struct ino_link *inop, Fchar separator, int max_depth ) { struct stat fs; Dir_t *dir; if (proc == 0) return; /* just make sure */ if (LSTAT(fn, &fs) < 0) { (*proc)(fn, strerror(errno), &fs); return; } /* report on file fn */ (*proc)(fn, (char*)0, &fs); if (max_depth == 0) return; if ((fs.st_mode & S_IFMT) != S_IFDIR) return; #ifdef S_IFLNK /* don't follow links */ if ((fs.st_mode & S_IFMT) == S_IFLNK) return; #endif /* treat directory */ if (dev < 0) { /* no device known yet */ dev = fs.st_dev; } if (fs.st_dev != dev) { return; } dir = Opendir(fn); if (dir == 0) { (*proc)(fn, "directory not readable", &fs); } else { /* scan new directory */ int fnl = Fnamelen(fn); Dirent_t *dent; struct ino_link ino; /* worry about loops in the file system */ if (in_ino_list(inop, &fs)) { (*proc)(fn, "loop in file system", &fs); Closedir(dir); return; } link_ino_list(inop, &ino, &fs); /* shape up the directory name */ if (fn[fnl-1] != separator) { /* append separator */ fn[fnl++] = separator; fn[fnl] = '\0'; } /* descend */ while ((dent = Readdir(dir)) != (Dirent_t *)0) { if ( Fnamecmp(dent->d_name, str2Fname(".")) == 0 || Fnamecmp(dent->d_name, str2Fname("..")) == 0 ) continue; if (Fnamecmp(dent->d_name, str2Fname("")) == 0) { (*proc)(fn, "directory contains empty file name", &fs ); continue; } /* append name */ Fnamecat(fn, dent->d_name); do_FEF(fn, proc, dev, &ino, separator, max_depth-1); /* remove name again*/ fn[fnl] = '\0'; } Closedir(dir); } }
/* =========================================================================== * Process a name or wildcard expression to operate on (or exclude). * We will only arrive here if we do a Freshen or Delete. * Return an error code in the ZEN_ class. * ZEN_OK, ZEN_ABORT, ZEN_MISS03, ZEN_MISS04, ZEN_MISS05, ZEN_MEM22, ZEN_MEM23 *ArgName :: Name to process. */ int procname( char *ArgName, bool RecurseDir, struct Globals *pG ) { char *a; /* path and name for recursion */ zDIR *d; /* directory stream from opendir() */ char *e; /* pointer to name from readd() */ int m; /* matched flag */ char *p; /* path for recursion */ int pnError; /* ProcName error */ struct stat StatRes; /* result of stat() */ struct zlist *z; /* steps through zfiles list */ // sprintf( ewemsg, "in procname name=>%s<= recurse=%d", ArgName, RecurseDir ); // diag( ewemsg ); m = 1; /* set dflt for success indicator (0=success) */ if ( pG->global_abort_sw ) return ZEN_ABORT; /* RCV changed was ZEN_MISS? */ if ( *ArgName == '\0' ) return ZEN_MISS03; /* LSSTAT returns 0 if it's arg is any kind of file (even a dir). */ /* IsShExp returns true if a wildcard symbol is found, or * NULL if none were found -- IsShExp is in util.c */ if ( LSSTAT( GetFullPath( pG, ArgName ), &StatRes ) || (IsShExp( ArgName ) != NULL) ) { // diag( "not a file or dir - 'ArgName' must be a wildcard fspec" ); // Upon finding a wildcard fspec, we need to mark entries in // the "zfiles" list that are included by the wildcard. /* convert the "external" (native) filename to an internal * ZIP-archive-compatible filename. */ p = ex2in( ArgName, (int *)NULL, pG ); /* shouldn't affect matching chars */ /* does any file already in the archive match this spec? */ /* Note that we need the pathname and filename together for this */ for ( z = pG->zfiles; z; z = z->nxt ) { if ( dosmatch( p, z->zname, pG ) ) { /* name is in archive - mark it for updating */ z->mark = pG->pcount ? filter( z->zname, pG ) : 1; FREE( z->name ); // RCV added + next 8 lines needed for FRESHEN mode. if ( (z->name = MALLOC( lstrlen( z->zname ) + 4 )) == NULL ) return ZEN_MEM34; z->name[0] = '\0'; //v1.55 if ( isalpha( ArgName[0] ) && ArgName[1] == ':' && ArgName[2] == '\\') { z->name[0] = ArgName[0]; z->name[1] = ArgName[1]; z->name[2] = ArgName[2]; z->name[3] = '\0'; } lstrcat( z->name, z->zname ); if ( pG->verbose ) printf( "%scluding %s\n", z->mark ? "in" : "ex", z->name ); m = 0; /* we had at least one file in the archive that we marked */ } } FREE( p ); /* returns 1 if no "zfiles" entries were marked, * 0 if at least one entry was marked */ if ( m ) { // diag( "returning ZEN_MISS04 from procname" ); return ZEN_MISS04; } // diag( "returning ZEN_OK from procname" ); return ZEN_OK; } /* end of "if (LSSTAT..." */ /* Existing and good filename or directory-- add the name if it's a file, recurse if directory */ // diag( "good entry to add, or a dir to go into" ); /* check the status returned by LSSTAT earlier to see if 'ArgName' is a dir */ pnError = ZEN_OK; if ( !(StatRes.st_mode & S_IFDIR) ) { /* it's not a directory - add file to found list */ sprintf( pG->ewemsg, "spot 1: Add file %s to found list", ArgName ); diag( pG->ewemsg, pG ); /* newname (fileio.c) adds to found list. If error m!=0 on return */ if ( (m = newname( ArgName, StatRes.st_size, pG )) != ZEN_OK ) { sprintf( pG->ewemsg, "returning %d from procname after newname call", m ); diag( pG->ewemsg, pG ); return m; } } else { /* It is a directory - Add trailing / to the directory name */ // diag( "Spot 2, directory found" ); if ( (p = MALLOC( lstrlen( ArgName )+ 2) ) == NULL ) return ZEN_MEM22; if ( !strcmp( ArgName, "." ) || !strcmp( ArgName, "\\." ) ) { // SLASH *p = '\0'; /* avoid "./" prefix and do not create zip entry */ } else { // diag( "spot 3" ); lstrcpy( p, ArgName ); a = p + lstrlen( p ); if ( a[-1] != '\\' ) lstrcpy( a, "\\" ); // SLASH /* newname (fileio.c) adds to found list. If error m != 0 on return */ if ( pG->dirnames && (m = newname( p, 0, pG )) != ZEN_OK ) { FREE( p ); sprintf( pG->ewemsg, "returning %d from procname after 2nd newname call", m ); diag( pG->ewemsg, pG ); return m; } } /* recurse into directory */ // diag( "spot 4: optional recurse into dir" ); if ( RecurseDir && ((d = Opendir( ArgName, pG )) != NULL) ) { /* Open new dir (like chdir) */ // diag( "good open of dir" ); while ( (e = readd( d, pG )) != NULL ) { if ( pG->global_abort_sw ) { // RCV changed error handling pnError = ZEN_ABORT; break; } /* e is pointing to the new filename we just read from dir */ /* ignore dir entries of . and .. */ if ( strcmp( e, "." ) && strcmp( e, ".." ) ) { /* get a new tmp buffer for the path and fname */ if ( (a = MALLOC( lstrlen( p ) + lstrlen( e ) + 1 )) == NULL ) { pnError = ZEN_MEM23; /* RCV error handling changed */ break; } /* form the new dir's pathname followed by the fname just read */ /* (we need to send in the dir and fname, or it won't be * detected as a valid file by LSSTAT) */ lstrcat( lstrcpy( a, p ), e ); // diag( "DOING RECURSIVE CALL TO PROCNAME FROM PROCNAME" ); if ( (m = procname( a, RecurseDir, pG )) != ZEN_OK ) { /* recursive call failed; return code not ZEN_OK */ if ( m != ZEN_OK && m != ZEN_MISS05 ) { /* unknown error; RCV error handling changed */ pnError = m; FREE( a ); break; } else if ( (int)(char)(m & 0xFF) == ZEN_MISS ) zipwarn( "name not matched: ", a ); } FREE( a ); } } /* end while */ Closedir( d ); } /* end if (spot 4) */ FREE( p ); } /* (StatRes.st_mode & S_IFDIR) == 0) */ // diag( "returning ZEN_ class from procname" ); return pnError; }
/* =========================================================================== * If not in exclude mode, expand the pattern based on the contents * of the file system. * This function is used while gathering filenames to be added or updated *w :: Path/pattern to match. Possible return values: ZEN_MISS, ZEN_OK, ZEN_ABORT, ZEN_MEM or ZEN_PARMS. */ int Wild( char *w, struct Globals *pG ) { zDIR *d; /* Stream for reading directory */ char *e; /* File or directory name found. */ char *n; /* Constructed name from directory */ int WError; /* Result of Wild() */ char *p, *a; /* path originale and fixed. */ char *q; /* Filename / pattern. */ int r; /* Result / temp var. */ char v[5]; /* space for device current directory.*/ bool StopRecurs = false; /* No recursion if filespec is file. */ // sprintf( pG->ewemsg, "in Wild of win32zip.c, pattern=%s recurse=%d", w, pG->recurse ); // diag( pG->ewemsg, pG ); // "zip -$ foo a:" can be used to force a drive name once. // v1.6017 if ( pG->volume_label == 1 ) { pG->volume_label = 2; pG->label = getVolumeLabel( pG, (w != NULL && w[ 1 ] == ':') ? to_up( w[ 0 ] ) : '\0', &pG->label_time, &pG->label_mode, &pG->label_utim ); if ( pG->label != NULL ) (void)newname( pG->label, 0, pG ); if ( w == NULL || (w[1] == ':' && w[2] == '\0') ) return ZEN_OK; } /* Allocate and copy pattern */ if ( (p = a = MALLOC( lstrlen( w ) + 1) ) == NULL ) return ZEN_MEM19; lstrcpy( p, w ); /* Separate path and name into p and q */ // We have '\' or '\name' or 'path1\path2\name2' or 'C:\path\name' but NOT 'C:\name' if ( (q = strrchr( p, '\\' )) != NULL && (q == p || q[-1] != ':') ) { // SLASH *q++ = '\0'; if ( *p == '\0' ) p = lstrcpy( v, "\\." ); /* if path is just '\' SLASH */ } else if ( (q = strrchr( p, ':' )) != NULL ) { /* We have 'C:' or 'C:\' or 'C:\name' */ *q++ = '\0'; p = lstrcat( lstrcpy( v, p ), ":" ); /* copy device as path eg. 'C:' */ if ( *q == '\\' ) { /* -> device:/., name eg. 'C:\.' SLASH */ lstrcat( p, "\\" ); // SLASH q++; /* name or nothing. */ } lstrcat( p, "." ); /* eg. 'C:.' or 'C:\.' */ } else if ( pG->recurse && (!strcmp( p, "." ) || !strcmp( p, ".." )) ) { /* current or parent directory */ /* Get "zip -r foo ." to work. Allow the dubious "zip -r foo .." but * reject "zip -r -m foo ..". "dispose" means wipe out source path. */ if ( pG->dispose && !strcmp( p, ".." ) ) ziperr( ZEN_PARMS15, pG ); q = (char *)pG->wild_match_all; } else { /* no path or device */ q = p; p = lstrcpy( v, "." ); } if ( pG->recurse && *q == '\0' ) q = (char *)pG->wild_match_all; /* take out a possibly redundant dir name of "." */ if ( (r = lstrlen( p )) > 1 && (strcmp( p + r - 2, ":." ) == 0 || strcmp( p + r - 2, "\\." ) == 0) ) // SLASH *(p + r - 1) = '\0'; /* Only filename (not the path) can have special matching characters */ if ( IsShExp( p ) ) { diag( "path has illegal chars", pG ); FREE( a ); return ZEN_PARMS16; } // sprintf( ewemsg, "at break up place in Wild: path=%s name=%s", p, q ); // diag( ewemsg ); if ( !IsShExp( q ) ) { // Speed up checking if file exits in case there are no wildcards struct stat s; // and no recursion and no archiving v1.6016 if ( !pG->recurse && !pG->ArchiveFiles ) { if ( !LSSTAT( GetFullPath( pG, w ), &s ) ) /* file exists ? */ return procname( w, false, pG ); return ZEN_MISS02; /* woops, no wildcards where is the file! */ } if ( pG->norecursefiles ) StopRecurs = true; } /* Now that we have a dir spec, along with an fspec, we'll step * in the dir specified to see if there's any matches against the fspec. */ WError = ZEN_MISS02; if ( (d = Opendir( p, pG )) != NULL ) { while ( (e = readd( d, pG )) != NULL ) { if ( pG->global_abort_sw ) { WError = ZEN_ABORT; break; } // sprintf( ewemsg, "Found %s: %s", d->d_attr & FILE_ATTRIBUTE_DIRECTORY ? "directory" : "file", e ); // diag( ewemsg ); /* if e is NOT '.' or '..', and is a dir or match fspec. */ if ( strcmp( e, "." ) && strcmp( e, ".." ) && (d->d_attr & FILE_ATTRIBUTE_DIRECTORY || dosmatch( q, e, pG )) ) { // diag( "Matched" ); /* we matched fspec or it's a dir and entry is not '.' or '..' */ if ( d->d_attr & FILE_ATTRIBUTE_DIRECTORY ) { // We do not save dirs or go into dirs if norecursefiles==1 and we a file without * or ? specs. if ( !StopRecurs && (pG->dirnames || pG->recurse) ) { if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + lstrlen( q ) + 3 )) == NULL ) { WError = ZEN_MEM20; break; } *n = '\0'; if ( *p != '.' ) AddSlash( lstrcpy( n, p ) ); // No ./ as first dir. lstrcat( n, e ); if ( pG->dirnames ) { // Save directory names also. r = procname( n, false, pG ); if ( (int)(char)(r & 0xFF) > ZEN_OK || !pG->recurse ) FREE( n ); if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; } if ( pG->recurse ) { // Recursively go into dir and check for other pattern matches. r = Wild( lstrcat( AddSlash( n ), q ), pG ); // Add the original pattern. FREE( n ); // We keep a ZEN_OK even when ZEN_MISS occurs. if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; // An error, stop processing. } } } else { if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + 2 )) == NULL ) { WError = ZEN_MEM21; break; } if ( !strcmp( p, "." ) ) r = procname( e, false, pG ); else r = procname( lstrcat( AddSlash( lstrcpy( n, p ) ), e ), false, pG ); FREE( n ); if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; } } /* end "if (strcmp..." */ } /* end while */ Closedir( d ); } else diag( "can't open dir", pG ); FREE( a ); // sprintf( ewemsg, "Wild returned: %d", WError ); // diag( ewemsg ); return WError; }