D
David Farning
I am new to c and not yet sure of the boundary between c and it's
implementations. So please redirect me if this should be asked elsewhere.
I am working on a function to determine if a directory exists. The idea
comes from a snippet I found in a samba source file.
bool dirExist(char *dname)
{
struct stat *stbuf;
//stbuf = (struct stat*)malloc(sizeof(struct stat));
bool ret;
if (stat(dname,stbuf) != 0)
return(False);
ret = S_ISDIR(stbuf->st_mode);
if(!ret)
errno = ENOTDIR;
printf("%s\n",ret);
return ret;
}
It seems to agree with page 180 of K&R2.
When passed a none existant directory name, it correctly reports a failure.
Yet, when passed a existant dir it segfaults at
stat(dname,stbuf)
Mallocing stbuf was just something I have been trying--didn't fix anything.
Thanks
Dave Farning
implementations. So please redirect me if this should be asked elsewhere.
I am working on a function to determine if a directory exists. The idea
comes from a snippet I found in a samba source file.
bool dirExist(char *dname)
{
struct stat *stbuf;
//stbuf = (struct stat*)malloc(sizeof(struct stat));
bool ret;
if (stat(dname,stbuf) != 0)
return(False);
ret = S_ISDIR(stbuf->st_mode);
if(!ret)
errno = ENOTDIR;
printf("%s\n",ret);
return ret;
}
It seems to agree with page 180 of K&R2.
When passed a none existant directory name, it correctly reports a failure.
Yet, when passed a existant dir it segfaults at
stat(dname,stbuf)
Mallocing stbuf was just something I have been trying--didn't fix anything.
Thanks
Dave Farning