Thread: opendir failure

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    opendir failure

    [IGNORE THIS POST]

    In my previous thread (http://cboard.cprogramming.com/showthread.php?t=104964) I was trying to find out why opendir would sometimes fail in a script which recurses thru a directory tree. No one could tell me so I wrote a simple test:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <dirent.h>
    #include <errno.h>
    
    int main (int argc, char *argv[]) {
            struct dirent *dcon;
            DIR *dir = opendir (argv[1]);
            if (dir == NULL) { 
                    printf ("&#37;s: %s\n", argv[1], strerror(errno)); 
                    exit(1);
            }
                
            while (dcon = readdir (dir)) {
                    puts (dcon->d_name);
            }       
    }
    Low and behold, this fails on every fourth or five directory i try it on, regardless of the pathname, length, ownership, or permissions (the error is "No such file or directory"). Since zacs7 tested the other script and got the same result, it can't be filesystem corruption...however we both use linux/GNU and (I presume) the GNU C libraries.

    Can anyone explain the problem?
    Last edited by MK27; 07-10-2008 at 11:44 AM. Reason: personal failures

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 01:03 PM
  3. php: glob() vs opendir() and friends
    By MisterSako in forum Tech Board
    Replies: 1
    Last Post: 03-16-2006, 01:42 AM
  4. CreateWindow failure
    By TheDan in forum Windows Programming
    Replies: 6
    Last Post: 07-08-2005, 07:49 AM
  5. Am i a Failure?
    By Failure!!! in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 05-28-2003, 11:50 AM