Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1753880
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2012-01-14 01:03:58



  1. #include "apue.h"
  2. int
  3. main(int argc,char * argv[] )
  4. {
  5.     int i;
  6.     struct stat buf;
  7.     char *ptr;

  8.     for( i = 1; i < argc ; i++)
  9.     {
  10.         printf("%s:",argv[i]);
  11.         if (lstat(argv[i],&buf) < 0) {
  12.             err_ret("lstat error ");
  13.          continue;
  14.      }

  15.             if ( S_ISREG(buf.st_mode))
  16.                  ptr = "regular";
  17.         else if ( S_ISDIR(buf.st_mode))
  18.             ptr = "direcotry ";
  19.         else if ( S_ISCHR(buf.st_mode))
  20.             ptr = "character special ";
  21.         else if ( S_ISBLK(buf.st_mode))
  22.             ptr = "block special ";
  23.         else if ( S_ISFIFO(buf.st_mode))
  24.             ptr = "FILE special ";
  25.         else if ( S_ISLNK(buf.st_mode))
  26.             ptr = "link special ";
  27.         else if ( S_ISSOCK(buf.st_mode))
  28.                         ptr = "sock special ";
  29.         else
  30.             ptr =" ** unknown mode ** ";
  31.         printf("%s\n",ptr);
  32.     }
  33.     exit(0);
  34. }

 output of the test:
 ./c4-1.c  /etc/password /etc /edev/in 
itctl /dev/log /dev/tty \ /dev/scsi/host0/bufs0/target0/lun0/cd /vdev/cdrom
/etc/password:lstat error ;No such file or directory
/etc:direcotry 
/dev/initctl:lstat error ;No such file or directory
/dev/log:sock special 
/dev/tty:character special  
/dev/scsi/host0/bus0/target0/lun0/cd:lstat error ;No such file or directory
/dev/cdrom:link  special  

阅读(1187) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~