zoukankan      html  css  js  c++  java
  • 程序4-1 对每个命令行参数打印文件类型

     1 //http://blog.chinaunix.net/uid-24549279-id-71355.html
     2 /*
     3  ============================================================================
     4  Name        : test.c
     5  Author      : blank
     6  Version     :
     7  Copyright   : Your copyright notice
     8  Description : 程序4-1 对每个命令行参数打印文件类型
     9  ============================================================================
    10 */
    11 
    12 #include <stdio.h>
    13 #include <sys/stat.h>
    14 #include "ourhdr.h"
    15 
    16 #define BUFFSIZE 4096
    17 
    18 int main(int argc, char *argv[])
    19 {
    20     int         i;
    21     struct stat buf;
    22     char        *ptr;
    23 
    24     for (i=1; i<argc; i++){
    25         printf("%s: ", argv[i]);
    26         if (lstat(argv[i], &buf) < 0){
    27             err_ret("lstat error");
    28             continue;
    29         }
    30 
    31         if (S_ISREG(buf.st_mode)){
    32             ptr = "regular";
    33         }else if(S_ISDIR(buf.st_mode)){
    34             ptr = "directory";
    35         }else if(S_ISCHR(buf.st_mode)){
    36             ptr = "character special";
    37         }else if(S_ISLNK(buf.st_mode)){
    38             ptr = "symbolic link";
    39         }else if (S_ISSOCK(buf.st_mode)){
    40             ptr = "socket";
    41         }else if(S_ISBLK(buf.st_mode)){
    42             ptr = "block special";
    43         }else if(S_ISFIFO(buf.st_mode)){
    44             ptr = "FIFO";
    45         }else{
    46             ptr = "***unknown mode***";
    47         }
    48         printf("%s
    ", ptr);
    49     }
    50     exit(0);
    51 }
  • 相关阅读:
    java设计模式简介
    java设计模式--单例模式
    判断整形回文数
    常用正则表达式 捕获组(分组)
    [转]十分钟搞定Vue搭建
    ActiveX界面已显示,调用方法报undefined的处理办法
    [转]纯js导出json到excel(支持chrome)
    webapi 开启gzip压缩
    webapi下载文件
    iis添加共享目录为虚拟目录
  • 原文地址:https://www.cnblogs.com/blankqdb/p/3693878.html
Copyright © 2011-2022 走看看