opendir after writing a file causes segmentation fault
Posted on 2006-06-29
I have a C program that creates files in a directory. At a later time, I try to open the directory to get the file names using opendir(). When I make the call a segmentation fault occurs. If files already exist in the directory, prior to creating any new files, opendir() works correctly. If there are no files in the directory prior to writing files, opendir() works correctly. It only fails when I create files in the directory, then perform opendir() on the directory.
The files are created rw-r--r-- and can be read without a problem with vi. I've verified that I always closedir() after a successful opendir(). I've verified that I call close() after the successful creat(). No errors are being generated from any of the calls.
The routine that creates the files is performed by a detached thread, while the routine that reads the directory is the boss thread. The debug log shows that the creating thread has completed the write and exited long before the read occurs.
Can anyone shed some light on what is causing the Segmentation fault? My project is on hold until I can resolve this issue.