#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int i;
struct stat buf;
char *ptr;
if(lstat(argv[1],&buf)<0)
{ printf("error"); return 0; }
if(S_ISREG(buf.st_mode)) ptr="普通文件";
else if(S_ISDIR(buf.st_mode)) ptr="目录文件";
else if(S_ISCHR(buf.st_mode)) ptr="字符特殊文件";
else if(S_ISBLK(buf.st_mode)) ptr="块特殊文件";
else if(S_ISFIFO(buf.st_mode)) ptr="管道或FIFO";
#ifdef S_ISLNK
else if(S_ISLNK(buf.st_mode)) ptr="符号链接";
#endif
#ifdef S_ISSOCK
else if(S_ISSOCK(buf.st_mode)) ptr="套接字";
#endif
printf("file type:%s\n",ptr);
return 0;
}