|
我只能判断一般文件、目录、块设备、字符设备,不知如何判断符号链结- #define T_FILE 0100000
- #define T_DIRECTORY 040000
- #define T_BLOCKDEVICE 060000
- #define T_BYTEDEVICE 020000
- #include <sys/types.h>
- #include <sys/stat.h>
- int main(int argc, char **argv)
- {
- struct stat statbuf;
- int tem;
- if(argc<2)
- {
- printf("usage: isdir filename");
- exit(0);
- }
- stat(argv[1],&statbuf);
- //printf("%s is 0%o \n",argv[1],statbuf.st_mode);
- tem=statbuf.st_mode&0777000;
- switch(tem)
- {
- case T_FILE:
- printf("%s is a file!",argv[1]);
- //printf("\t tem=0%o\n",tem);
- break;
- case T_DIRECTORY:
- printf("%s is a directory!",argv[1]);
- break;
- case T_BYTEDEVICE:
- printf("%s is a byte device!",argv[1]);
- break;
- case T_BLOCKDEVICE:
- printf("%s is a bolck device!",argv[1]);
- break;
- default:
- printf("isdir: %s: No such file or directory!",argv[1]);
- break;
- }
- //printf("\t tem=0%o\n",tem);
- }
复制代码 |
|