Re: open file or directory



On May 30, 12:53 pm, "Mr. X." <no_spam_please@xxxxxxxxxxxxxxxxx>
wrote:
Nothing special on code,
but what may be wrong,
(because even on directory, the follows runs :

Works for me. Post complete, compilable code.

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
if(argc==2)
{
int fd;
struct stat buf;
fd=open(argv[1], O_RDONLY);
if(fd<0) fprintf(stderr, "ouch\n");
if(fstat(fd, &buf)==-1) fprintf(stderr, "bad\n");
if(S_ISDIR(buf.st_mode)) printf("directory\n");
else printf("not directory\n");
}
}

$ ./t some_file
not directory

$ ./t some_dir
directory

DS

.



Relevant Pages