LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-26-2004, 06:37 AM   #1
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
opendir() SIGSEGV on RedHat 9


Hi all

I am running into a situation where the opendir() call crashes after one
iteration of a loop in which it is located. It does not return NULL or an
errno, it just kills the whole program with a SIGSEGV. I am using it to
open and read all subdirectories of a directory - the loop executes once
(for the first subdirectory) and when it is finished, closedir() is called
on the same DIR * variable that I then, in the next iteration, use again
with the next looped opendir() call to open the next subdirectory.

Anybody else ever encountered this? Why is opendir crashing with no null
returned and no error code? It only ever runs once - any second call during
the same run of the program SIGSEGV's the whole program.

How (if my assumption here is incorrect) do you traverse subdirectories? Is
this related to a buggy libc?

Thanks!
 
Old 05-26-2004, 08:36 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
A recursive function is generally the best (read easiest) way to traverse subdirectories. opendir() should be called once for the directory. Then you use readdir() in your loop to read in each file in that directory. After the readdir() loop you'd call closedir() on the directory.

Check the man pages for those functions for details.
 
Old 05-26-2004, 10:47 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Using scandir() may be easier.
And its man page has a nice simple example program.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
c++ opendir() handling error bendeco13 Programming 1 11-06-2005 02:37 AM
SIGSEGV everywhere !!! nolimitz Linux - Software 3 08-12-2005 10:14 AM
MD5, opendir, and other problems in Perl... KneeLess Programming 2 08-23-2004 02:15 PM
Opening a directory WITHOUT using 'opendir' and 'readdir' skywalker27182 Programming 2 11-16-2003 01:32 PM
perl opendir like function for php? paulish Programming 2 09-21-2003 03:45 AM

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

All times are GMT -5. The time now is 09:27 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