This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
stat problem ?
- To: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Subject: stat problem ?
- From: Borsos Zoltán <zoltan dot borsos at sysdata dot siemens dot hu>
- Date: Thu, 30 Mar 2000 08:31:09 +0200
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