Skip to contentSkip to conversation

ftw , nftw doesn't work

DISCUSSION Nikola 4 participants 4 messages Apr 25, 2007

lore
Share & tools
lore

Nikola

author
#0 lore raw

Hi,

I am trying to parse dir tree with ftw and nftw on Linux (debian) but without result.

------------------------------------------------------

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

int fn(const char *file, const struct stat *sb, int flag){

       printf("-->\n");
}

int main(int argc,char **argv){

       ftw("/etc/", fn, 5);

       return 0;
}

------------------------------------------------------

bash# gcc test.c
bash# ./a.out
-->
bash#

------------------------------------------------------

Does anyone knows what might be the problem.

tnx in advance.

#1 lore raw
Quoted 32 lines · On Wednesday 25 April 2007 08:45:27 Nikola wrote:

Hi,

I am trying to parse dir tree with ftw and nftw on Linux (debian) but without result.

------------------------------------------------------

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

int fn(const char *file, const struct stat *sb, int flag){

        printf("-->\n");
}

int main(int argc,char **argv){

        ftw("/etc/", fn, 5);

        return 0;
}

------------------------------------------------------

bash# gcc test.c
bash# ./a.out
-->
bash#

Quoted 6 lines

------------------------------------------------------

Does anyone knows what might be the problem.

tnx in advance.

The return value of fn should be 0 if you want the walk to continue past the first file or directory.

#2 lore raw
Quoted 36 lines · Stephen Kratzer
Quoted 34 lines · On Wednesday 25 April 2007 08:45:27 Nikola wrote:

Hi,

I am trying to parse dir tree with ftw and nftw on Linux (debian) but without result.

------------------------------------------------------

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

int fn(const char *file, const struct stat *sb, int flag){

        printf("-->\n");
}

int main(int argc,char **argv){

        ftw("/etc/", fn, 5);

        return 0;
}

------------------------------------------------------

bash# gcc test.c
bash# ./a.out
-->
bash#

------------------------------------------------------

Quoted 9 lines
Quoted 5 lines

Does anyone knows what might be the problem.

tnx in advance.

The return value of fn should be 0 if you want the walk to continue past the first file or directory.

and compiling with warning outputs could have helped, too :)

$ gcc -Wall test.c
surely leads to a "control reaches end of a non void function" or
something similar...

Ben

Signature · 2 lines
Purple Labs S.A.
www.purplelabs.com
#3 lore raw
In reply to Nikola
Quoted 3 lines · Nikola

int fn(const char *file, const struct stat *sb, int flag){

       printf("-->\n"); }

You don't actually print the file name here.

Leslie

Signature · 2 lines
NEW homepage: https://viridian.dnsalias.net/~sky/homepage/
gpg --keyserver pgp.mit.edu --recv-keys DD4EBF83