Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: opendir

Reply
Thread Tools

Re: opendir

 
 
viza
Guest
Posts: n/a
 
      07-08-2008
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
 
Reply With Quote
 
 
 
 
viza
Guest
Posts: n/a
 
      07-08-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a class similar to 'opendir' and 'readdir' Ramon Java 5 01-03-2005 01:59 PM
opendir doesn't work.. Markus Pitha C Programming 5 09-12-2004 02:40 PM
using "opendir" through a CGI script on Apache Alex Perl 2 02-10-2004 04:35 AM
opendir and if -d $files problem Bob Gervais Perl 1 11-12-2003 05:34 AM
opendir() Andrew Perl 2 09-03-2003 02:48 PM



Advertisments