14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*8462SApril.Chin@Sun.COM * Copyright (c) 1985-2008 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 7*8462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin /* 244887Schin * nftw implementation 254887Schin */ 264887Schin 274887Schin #include <ast.h> 284887Schin #include <ftw.h> 294887Schin 304887Schin static int nftw_flags; 314887Schin static int (*nftw_userf)(const char*, const struct stat*, int, struct FTW*); 324887Schin 334887Schin static int 344887Schin nftw_user(Ftw_t* ftw) 354887Schin { 364887Schin register int n = ftw->info; 374887Schin struct FTW nftw; 384887Schin struct stat st; 394887Schin 404887Schin if (n & (FTW_C|FTW_NX)) 414887Schin n = FTW_DNR; 424887Schin else if ((n & FTW_SL) && (!(nftw_flags & FTW_PHYSICAL) || stat(ftw->path, &st))) 434887Schin n = FTW_SLN; 444887Schin nftw.base = ftw->pathlen - ftw->namelen; 454887Schin nftw.level = ftw->level; 464887Schin nftw.quit = 0; 474887Schin n = (*nftw_userf)(ftw->path, &ftw->statb, n, &nftw); 484887Schin ftw->status = nftw.quit; 494887Schin return n; 504887Schin } 514887Schin 524887Schin int 534887Schin nftw(const char* path, int(*userf)(const char*, const struct stat*, int, struct FTW*), int depth, int flags) 544887Schin { 554887Schin NoP(depth); 564887Schin nftw_userf = userf; 574887Schin if (flags & FTW_CHDIR) flags &= ~FTW_DOT; 584887Schin else flags |= FTW_DOT; 594887Schin nftw_flags = flags; 604887Schin return ftwalk(path, nftw_user, flags, NiL); 614887Schin } 62