opendir() returns null but errno is zero

This is a discussion on opendir() returns null but errno is zero within the Linux Programming forums, part of the Platform Specific Boards category; I'm having a problem with some code I'm writing on linux to list files in a directory using opendir/readdir, where ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2,138

    opendir() returns null but errno is zero

    I'm having a problem with some code I'm writing on linux to list files in a directory using opendir/readdir, where opendir is returning NULL, but it's not setting errno to a useful value. I know for a fact that the directory I'm attempting to open exists, is a directory, I have access to it, there are not too many descriptors in use, there are not too many files open, and there is plenty of memory available. I'm really confused about this.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps posting the relevant code would help here... Sometimes someone else will spot the simple mistake that the person who wrote the code hasn't spotted.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,138
    this was the problem:

    Code:
    DIR* d = NULL;
    d = opendir("mydir");
    if (d == NULL);
    {
      switch (errno)
      {
        // print errno to screen here and report the error
      }
    }
    stupid mistake.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  2. Syntax Error??
    By Kennedy in forum C Programming
    Replies: 8
    Last Post: 09-06-2006, 11:04 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  4. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 03:43 AM
  5. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21