Reputation: 1
I'm trying to use the st_mode
from a returned stat
struct, that I get from the stat()
call following way;
char *fn = "test.c"
struct stat *buf = malloc(sizeof(stat));
stat(fn,buf);
if(S_ISREG(buf.st_mode))
{
printf("this file is a regular file..."); //if regular
}
When I try to compile this code, I get the following error:
server1.c: In function ‘main’:
server1.c:223:32: error: request for member ‘st_mode’ in something not
a structure or union
if(S_ISREG(fileData.st_mode))
^
Why do I get this compile error? I can't seem to find much info myself..
Upvotes: 0
Views: 926
Reputation: 58848
buf
is not a struct stat
. buf
is a pointer to a struct stat
, and pointers don't have st_mode
fields. To get the st_mode
field of the struct stat
that buf
points to, use (*buf).st_mode
, or buf->st_mode
for short.
Upvotes: 1