LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2006, 03:51 AM   #1
Maestro485
Member
 
Registered: Apr 2004
Location: Pittsburgh
Distribution: Slackware
Posts: 136

Rep: Reputation: 16
Recovering when nftw() returns -1


I'm using the nftw() system call in a program I am writing and it returns -1 (error) every time it comes across a directory that is part of an active torrent download. I was wondering if there is a conventional way to cause nftw() to skip the file that gives it trouble and continue walking the file tree.

Thanks,
Matt Bragano
 
Old 08-08-2006, 10:28 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
If you are getting (-1) and EINVAL, EINVAL is not an error code set by either fstat or ftw(). It has to be coming from your callback function. Something in that function fails, it is not an nftw() problem.

This is how nftw works - if the nftw function itself fails it returns -1. If the (l/f)stat call it makes it returns (-1) nftw quits and returns (-1). You can control this behavior. If your fn() returns with anything but zero,
nftw bails out and returns that value. Since errno is EINVAL and stat and nftw do not set that error code, then your function has to be doing it.
 
Old 08-14-2006, 01:29 PM   #3
Maestro485
Member
 
Registered: Apr 2004
Location: Pittsburgh
Distribution: Slackware
Posts: 136

Original Poster
Rep: Reputation: 16
Thanks for the quick response. I went ahead and implemented a quick test callback function that just prints the name of the files encountered by nftw() to cout and returns 0, and nftw() still returns -1 when it encounters the same problem file described earlier. Also, the program runs solid on other computers I've tried it on.

Any ideas on tracking down the source of the problem? Or even just finding a way to skip the problem file and let nftw() continue?

Thanks,
Matt Bragano
 
Old 08-16-2006, 01:13 PM   #4
Maestro485
Member
 
Registered: Apr 2004
Location: Pittsburgh
Distribution: Slackware
Posts: 136

Original Poster
Rep: Reputation: 16
I just discovered the meaning behind the error using perror(). It is returning EOVERFLOW because "Value too large for defined data type." This occurs when:

A field in the stat structure cannot be represented correctly in the current programming environment for one or more files found in the file hierarchy.

I'll keep playing with it to see if I can work around this somehow. It is failing on a rather large file (a DVD iso image) so that is probably the source.

Matt
 
Old 08-16-2006, 04:06 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
struct stat.st_size may be overflowing.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nftw question? linbl352 Programming 6 05-23-2006 08:04 PM
Carriage Returns Thorkyl Linux - Software 7 06-28-2004 05:42 PM
c difftime returns zero mr.neil Programming 3 06-02-2004 12:43 PM
mktime() returns -1 nodger Programming 2 01-27-2004 04:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration