Survi Makharia
Survi Makharia

Reputation: 81

how to specify nftw flags

This is my nftw function, it works correctly before specifying flags FTW_DEPTH and FTW_PHYS:

if (nftw(argv[1], visit, 64, FTW_DEPTH | FTW_PHYS) != 0) 
{
    perror("nftw");
}

Also I have defined visit as:

int visit(const char *path, const struct stat *stat, int flags)
{
    ...
    return 0;
}

BUT after compilation it gives error:

‘FTW_DEPTH’ undeclared (first use in this function)

Upvotes: 3

Views: 2250

Answers (2)

Moh3N
Moh3N

Reputation: 75

if you look at ftw.h you see these lines :

#ifdef __USE_XOPEN_EXTENDED
/* Flags for fourth argument of `nftw'.  */
enum
{
  FTW_PHYS = 1,     /* Perform physical walk, ignore symlinks.  */
  # define FTW_PHYS FTW_PHYS
  FTW_MOUNT = 2,    /* Report only files on same file system as the
           argument.  */
  # define FTW_MOUNT    FTW_MOUNT
  FTW_CHDIR = 4,    /* Change to current directory while processing it.  */
  # define FTW_CHDIR    FTW_CHDIR
  FTW_DEPTH = 8     /* Report files in directory before directory itself.*/
  # define FTW_DEPTH    FTW_DEPTH
  # ifdef __USE_GNU
  ,
  FTW_ACTIONRETVAL = 16 /* Assume callback to return FTW_* values instead of
           zero to continue and non-zero to terminate.  */
  #  define FTW_ACTIONRETVAL FTW_ACTIONRETVAL
  # endif
};

so you can define this flag and error would be resolved:

#define __USE_XOPEN_EXTENDED 

Upvotes: 0

Jaydeep
Jaydeep

Reputation: 41

Try using #define _XOPEN_SOURCE 500 before including ftw.h

Upvotes: 3

Related Questions