1

I want to use nftw() and be only on first lvl deep. But it still goes deeper, even if I specify FTW_MOUNT. Next I want to check if files is simple file, and do something with it. This is what i tried:

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <ftw.h>

int ftwinfo(const char *p, const struct stat *st, int fl, struct FTW *fbuf);

int ftwinfo(const char *p, const struct stat *st, int fl, struct FTW *fbuf){
   static int cnt = 0;
   puts( p );
   cnt++;
   if( cnt >= 10 ) return cnt;
   return 0;
}

int main(int argc,char* argv[]){
   int rv;
   int flags = FTW_MOUNT;
   rv = nftw( ".", ftwinfo, 20, flags );
   if( rv == -1 ){
      perror( "nftw failed" );
      exit( 1 );
   }
   if( rv != 0 ){
      printf( "ntfw fn function returnd %d != 0 -> nftw finished\n", rv );
   }
   return 0;
}
Emilis
  • 152
  • 1
  • 4
  • 21
  • You probably need `FTW_SKIP_SUBTREE` instead of `FTW_MOUNT`, because the latter will only prevent `nftw` from crossing file-system boundaries. – Felix G May 12 '20 at 07:21

0 Answers0