Re: opendir

Discussion in 'C Programming' started by viza, Jul 8, 2008.

  1. viza

    viza Guest

    On Tue, 08 Jul 2008 12:25:42 -0500, MK wrote:

    > I don't use c much but I've done lots of perl, perl/Tk, and shellcode on
    > LINUX.
    >
    > I'm trying to do things with directory trees and i occasionally get back
    > an errno from opendir "No such file or directory" while my program is
    > working its way thru a tree. This always happens with the same
    > directory (ie. it is not totally random) although there is nothing
    > different or unusual about the ownership or permissions (ie. there
    > actually is such a readable directory).


    > strcpy(invalid, ".");
    > strcat(invalid, ".");


    Are you entering the IOCCC? That has got to be the world's most
    around-the-houses way to get ".." I have ever seen! What is wrong with
    strcmp( foo, ".." ) like that?

    Also, you declared:
    > char invalid[2],


    So you have overflowed the fixed length buffer right there (".." requires
    _three_ bytes).

    More likely to be the cause of the problem is:
    > stat(fullname,&dstuff);


    You must check the return value of stat(). It may tell when something is
    wrong.

    Perhaps trying lstat() may reveal something, too. I'm thinking in
    particular of a dangling symlink.

    Cross-posted and followup-to comp.unix.programmer. I'm not saying you
    can or can't use c.l.c for this (and am not really bothered what the
    various playground gangs have to say on the subject), but you will
    probably get better help there on this problem.

    HTH
    viza
    viza, Jul 8, 2008
    #1
    1. Advertising

  2. viza

    viza Guest

    On Tue, 08 Jul 2008 18:51:29 +0000, Richard Heathfield wrote:
    > viza said:
    >> On Tue, 08 Jul 2008 12:25:42 -0500, MK wrote:


    >>> strcpy(invalid, ".");
    >>> strcat(invalid, ".");

    >>
    >> Are you entering the IOCCC? That has got to be the world's most
    >> around-the-houses way to get ".." I have ever seen! What is wrong with
    >> strcmp( foo, ".." ) like that?

    >
    > Think about it. What do /you/ think is wrong with strcmp in this
    > context?


    I didn't mean to use :

    strcmp( invalid, ".." );

    in place of:

    strcat( invalid, "." );
    strcpy( invalid, "." );

    I meant to use:

    if( ! strcmp( some_string, ".." ))

    in place of:

    strcat( invalid, "." );
    strcpy( invalid, "." );
    if( ! strcmp( some_string, invalid ))

    Perhaps I trimmed a bit too much of the code there. It's in the OP.

    viza
    viza, Jul 8, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew

    opendir()

    Andrew, Sep 3, 2003, in forum: Perl
    Replies:
    2
    Views:
    9,456
    John Bokma
    Sep 3, 2003
  2. Bob Gervais

    opendir and if -d $files problem

    Bob Gervais, Nov 7, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,636
    Steve Grazzini
    Nov 12, 2003
  3. Alex
    Replies:
    2
    Views:
    692
  4. Ramon
    Replies:
    5
    Views:
    10,775
    John C. Bollinger
    Jan 3, 2005
  5. Markus Pitha

    opendir doesn't work..

    Markus Pitha, Sep 12, 2004, in forum: C Programming
    Replies:
    5
    Views:
    463
    Markus Pitha
    Sep 12, 2004
Loading...

Share This Page