Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > readdir() and S_ISDIR(stat.st_mode) question (OT ?)

Reply
Thread Tools

readdir() and S_ISDIR(stat.st_mode) question (OT ?)

 
 
electric sheep
Guest
Posts: n/a
 
      03-04-2004
I'm not sure if this is POSIX or not ... and indeed if POSIX
is OT here or not, but if the subject made sense to you ....

I have a very simple program here, but it seems to be returning
a "true" value to the query S_ISDIR() even when the directory
entry is not a directory.

#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>

int main(int argc, char *argv[]) {
DIR *dir;
struct dirent *entry;
struct stat eStat;
char *root;
int i;

root = argv[1];

while((entry = readdir(dir)) != NULL) {
lstat(entry->d_name, &eStat);
if(S_ISDIR(eStat.st_mode))
printf("found directory %s\n", entry->d_name);
else
printf("not a dir\n");
}
return 0;
}


sample output:
found directory .
found directory ..
found directory NCURSES-Programming-HOWTO-html.tar.gz
found directory ncurses_programs
found directory ncurses.html

 
Reply With Quote
 
 
 
 
Martien Verbruggen
Guest
Posts: n/a
 
      03-04-2004
On Thu, 04 Mar 2004 05:08:53 GMT,
electric sheep <(E-Mail Removed)> wrote:
> I'm not sure if this is POSIX or not ... and indeed if POSIX
> is OT here or not, but if the subject made sense to you ....


Yes, it is a POSIX question, and it is offtopic here.

comp.unix.programmer is the place where they discuss POSIX.

Martien
--
|
Martien Verbruggen | Think of the average person. Approximately
Trading Post Australia | half of the people out there are dumber.
|
 
Reply With Quote
 
 
 
 
Villy Kruse
Guest
Posts: n/a
 
      03-04-2004
On 04 Mar 2004 05:28:37 GMT,
Martien Verbruggen <(E-Mail Removed)> wrote:


> On Thu, 04 Mar 2004 05:08:53 GMT,
> electric sheep <(E-Mail Removed)> wrote:
>> I'm not sure if this is POSIX or not ... and indeed if POSIX
>> is OT here or not, but if the subject made sense to you ....

>
> Yes, it is a POSIX question, and it is offtopic here.
>
> comp.unix.programmer is the place where they discuss POSIX.
>



Regardless of that, it is still a good idea to check possible errors
also from non-ANSI-C functions.


Villy
 
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
question about .h file and .cpp file,also compiler question key9 C++ 7 09-13-2006 06:45 PM
Thanks (and apologies) for your comments on "The Most Obvious Question You Are Ever Likely To See" (e.g. No-Brainer security question) Curious George Computer Security 1 03-14-2005 10:01 PM
Re: General USB Printer setup question, and situation-specific question AG A+ Certification 0 01-13-2005 11:13 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM
newbie delurking, a lighting question, and a pricing question verminiusrex Digital Photography 2 08-08-2003 10:10 PM



Advertisments