Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7548
  • 博文数量: 14
  • 博客积分: 250
  • 博客等级: 二等列兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-13 01:08
文章分类
文章存档

2011年(14)

我的朋友
最近访客

分类: IT职场

2011-01-13 03:23:50

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. static int ftype(const char *path)
  6. {
  7.         struct stat statres;
  8.         if(lstat(path, &statres) < 0)
  9.         {
  10.                 return -1;
  11.         }
  12.         if(S_ISREG(statres.st_mode))
  13.         {
  14.                 return '-';
  15.         }
  16.         if(S_ISCHR(statres.st_mode))
  17.         {
  18.                 return 'c';
  19.         }
  20.         if(S_ISBLK(statres.st_mode))
  21.         {
  22.                 return 'b';
  23.         }
  24.         if(S_ISFIFO(statres.st_mode))
  25.         {
  26.                 return 'p';
  27.         }
  28.         if(S_ISLNK(statres.st_mode))
  29.         {
  30.                 return 'l';
  31.         }
  32.         if(S_ISDIR(statres.st_mode))
  33.         {
  34.                 return 'd';
  35.         }
  36.         if(S_ISSOCK(statres.st_mode))
  37.         {
  38.                 return 's';
  39.         }
  40.         return '?';
  41. }
  42. int main(int argc, char **argv)
  43. {
  44.         if(argc < 2)
  45.         {
  46.                 fprintf(stderr, "Usage...\n");
  47.                 exit(1);
  48.         }
  49.         printf("%c\n", ftype(argv[1]));
  50.         exit(0);
  51. }
  52. ~
  53. ~
  54. ~
  55. ~
阅读(184) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~