分类: C/C++
2007-10-28 19:49:28
wangyao@fisherman:~/pinggu/exp2/half_open$ cat t_isdir.c #include #include #include #include #define ISDIR(path) opendir(path)==NULL?0:1 int isdir_opendir(const char *path) { if( opendir(path) ) return 1; else return 0; } int isdir_lstat(char *path) { struct stat buf; if( lstat(path,&buf) != 0) { perror("lstat error"); return 0; } if( S_ISDIR(buf.st_mode) ) return 1; else return 0; } int main(int argc,char *argv[]) { int temp; temp = ISDIR(argv[1]); /* temp = isdir_opendir(argv[1]); temp = isdir_lstat(argv[1]); */ if(temp) printf("%s is DIR.\n",argv[1]); else printf("%s is not DIR.\n",argv[1]); return 0; } |