Chinaunix首页 | 论坛 | 博客
  • 博客访问: 532699
  • 博文数量: 150
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 00:19
文章分类

全部博文(150)

文章存档

2011年(1)

2009年(14)

2008年(135)

我的朋友

分类: LINUX

2008-08-31 10:31:19



/*==========================================================

DESCRIPTION:print type of file for each commond-line argument

============================================================*/


#include<sys/stat.h>
#include<stdio.h>

int main( int argc , char *argv[])
{
  int i;
  struct stat statbuffer;

  if( argc<2 ){
    printf( " argument is not enough\n " );
    return;
  }

  for( i=1; i<argc ; i++){
      printf( "%s:" , argv[i] );
      if( stat(argv[i] , &statbuffer)<0 ){
          perror( "stat function failed:" );
      }

      if( S_ISREG(statbuffer.st_mode) ){
          puts( "regular file\n" );
      }
      else if( S_ISDIR(statbuffer.st_mode) ){
          puts( "directory\n" );
      }
      else if( S_ISLNK(statbuffer.st_mode)){
          puts( "link file\n" );
      }
      else if( S_ISCHR(statbuffer.st_mode) ){
         puts( "character file\n" );
      }
      else if( S_ISBLK(statbuffer.st_mode) ){
         puts( "block device\n" );
      }
      else if( S_ISFIFO(statbuffer.st_mode) ){
         puts( "FIFO file\n" );
      }
      else if( S_ISSOCK(statbuffer.st_mode) ){
         puts( "socket file \n" );
      }
      else{
         puts( "unknown mode" );
      }

  }
  return 0;

}

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