Re: open file or directory
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: 30 May 2007 14:09:28 -0700
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
.
- References:
- open file or directory
- From: Mr. X.
- Re: open file or directory
- From: Geoff Clare
- Re: open file or directory
- From: Mr. X.
- open file or directory
- Prev by Date: Re: fill array of char with char.
- Next by Date: Re: fill array of char with char.
- Previous by thread: Re: open file or directory
- Next by thread: Re: open file or directory
- Index(es):
Relevant Pages
|
|