Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning with nftw

Tags:

c

linux

unix

posix

I'm trying to use the nftw to process some files under a directory

#include <ftw.h>
#include <stdio.h>

 int wrapper(const char * fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
  printf("File %d\n", ftwbuf->base);
  return(0);
} 


int main(int argc, char ** argv) {
    const char *name;
    int flags = 0;
    name = argv[1];
    nftw(name, wrapper, 20, flags);
    return 0;

}

When I'm compiling (gcc kconfig_parser.c -o parser) , I've got this warning and this error..

kconfig_parser.c:5: warning: ‘struct FTW’ declared inside parameter list 
kconfig_parser.c:5: warning: its scope is only this definition or declaration, which is probably not what you want
kconfig_parser.c: In function ‘wrapper’:
kconfig_parser.c:6: error: dereferencing pointer to incomplete type

I've checked the definition of the struct and the prototype of the callback, and some examples, it should be fine... What am I doing wrong ? (I've removed almost everything of my code to clear it)...

thanks

like image 720
LB40 Avatar asked Apr 23 '09 15:04

LB40


2 Answers

On a CentOs versions the header file didn't use "#define _XOPEN_SOURCE 500" i had to do this below,

#define __USE_XOPEN_EXTENDED 1
#include <ftw.h>
like image 96
JohnMeg Avatar answered Sep 29 '22 13:09

JohnMeg


Linux, for some reason, still uses SUSv1 for this API, where nftw() is still considered an extension.

From the Linux manual page, the include has to be:

#define _XOPEN_SOURCE 500
#include <ftw.h>
like image 29
Juliano Avatar answered Sep 29 '22 12:09

Juliano