This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

stat problem ?


Hi everybody !

I'm new in this list and in C too.
I have written a small program that in one version dosen't work
but in the other does it. I'd like to ask the experts explain me the
difference between the programs.

I can compile both free from errors but when I let it run this version
give me the following message :

[main] D:\KOZOS\progik\c\exe\dirsiz_1.exe 1000 (0) handle_exceptions:
Exception:
 STATUS_ACCESS_VIOLATION
[main] dirsiz_1 1000 (0) handle_exceptions: Dumping stack trace to
dirsiz_1.exe.
core

// dirsiz_1.c

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

main(void) {

DIR *dp;
struct dirent *ep;
struct stat *st;
int rc;

dp = opendir ("./");
if (dp != NULL)
{
while (ep = readdir (dp)) 
{
rc=stat (ep->d_name,st);
if (S_ISDIR(st->st_mode)!=0)
	puts (ep->d_name);
else
	{
	printf ("Not a directory : ");
	puts(ep->d_name);
	printf("\n");
	}
}
(void) closedir (dp);
}
else
puts ("Couldn't open the directory.");
return;
}

-------------------------------------------------

This version works fine :

// dirsiz_2.c

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

main(void) {

DIR *dp;
struct dirent *ep;
struct stat st;
int rc;

dp = opendir ("./");
if (dp != NULL)
{
while (ep = readdir (dp)) 
{
rc=stat (ep->d_name,&st);
if (S_ISDIR(st.st_mode)!=0)
	puts (ep->d_name);
else
	{
	printf ("Not a directory : ");
	puts(ep->d_name);
	printf("\n");
	}
}
(void) closedir (dp);
}
else
puts ("Couldn't open the directory.");
return;
}

Thanks for the answers !
The answers please to my own address too.

Szambi

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]