need help in file traversal via FTS(3)


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users need help in file traversal via FTS(3)
# 1  
Old 10-09-2008
CPU & Memory need help in file traversal via FTS(3)

Hi friends,
I was trying to traverse a file using FTS(3) . this is the code below.. but I am getting segmentation error in the line fts_read(...) ,
anybody have any idea , why it is?
Please, help me. Thanks in advance.
-------------------------------------------------------------------------------------------------------
Program:
-------------------------------------------------------------------------------------------------------

FTS *fileStruct;
FTSENT *dirList, *fileInfo;
int ftsResult;

fileStruct = fts_open(&argv[1], FTS_COMFOLLOW, 0);
dirList = fts_children(fileStruct, FTS_NAMEONLY);
do
{
fileInfo = fts_read(dirList->fts_pointer);
fileStruct = fts_open((char * const *)dirList->fts_link->fts_name, FTS_PHYSICAL, (void *)result);

}while (dirList->fts_link != NULL);

ftsResult = fts_close(fileStruct);

-------------------------------------------------------------------------------------------------------
Result of Debugging:
-------------------------------------------------------------------------------------------------------
Starting program: a.out temp
0x0000000000400b78 in main ()
Current language: auto; currently asm
(gdb)
(gdb) n
Single stepping until exit from function main,
which has no line number information.

-- Done with option processing. -- optind is 1
first non-option arg: argv[1] = 'temp'
200810090259
destination directory path : temp/200810090259
checking
fileStruct is not null

Program received signal SIGSEGV, Segmentation fault.
0x00007fc797a4d5c8 in fts_read () from /lib/libc.so.6
(gdb) bt
#0 0x00007fc797a4d5c8 in fts_read () from /lib/libc.so.6
#1 0x0000000000400f4d in main ()
(gdb) Quit
(gdb)

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

Last edited by jack85; 10-09-2008 at 05:04 AM.. Reason: updated
# 2  
Old 10-10-2008
It has been resolved.

Thanks
...
# 3  
Old 10-10-2008
Just as an aside - ntfw() and ftw() are the POSIX (ie portable) functions for doing this kind of file tree walk. FTS has some neat features but it won't fly anywhere except linux.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

file traversal

Hi, I have to get some value of the from a flat file and my file format is like this. ABC DEF HIJ=1 XYZ xyz HIJ=2 So i need to make sure i get all the value of HIJ under XYZ and not ABC. (4 Replies)
Discussion started by: nidhink
4 Replies

4. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

5. Shell Programming and Scripting

AWK File Traversal

Hey, I'm working on a file traversal and extraction function and am having problems. So, my script is finding all files in a directory. Each file has the same format. I need to extract a field from the 4th line of each file..... hence why I am using the substring on NR == 4. So, I am... (11 Replies)
Discussion started by: beefeater267
11 Replies

6. Shell Programming and Scripting

Creating breadth traversal binary tree

I almost have the entire script written. however the problem is how would i assign the global variable to terminate the process from the bottom up to ensure the child terminates so the parent can. ex. I am proccess 1 I am proccess 2 etc Here is the code $ cat tree.c ... (3 Replies)
Discussion started by: slurpeyatari
3 Replies

7. UNIX for Dummies Questions & Answers

Command line traversal

What is a key, if on command line I have to trverse left & right word by word, instead of character by character? (7 Replies)
Discussion started by: videsh77
7 Replies
Login or Register to Ask a Question