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 }
  • 相关阅读:
    [SUCTF 2019]EasySQL
    [强网杯 2019]随便注
    [HCTF 2018]WarmUp
    Linux下配置JDK环境
    Centos克隆虚拟机后配置网络
    Sublime安装插件
    LeetCode-91-解码方法
    LeetCode-322-零钱兑换
    LeetCode-152-乘积最大子数组
    LeetCode-139-单词拆分
  • 原文地址:https://www.cnblogs.com/blankqdb/p/3693878.html
Copyright © 2011-2022 走看看