zoukankan      html  css  js  c++  java
  • mystate实现

    mystate伪代码实现如下

    struct stat {
        dev_t         st_dev;       //设备编号
        ino_t         st_ino;       //节点
        mode_t        st_mode;      //类型和存取的权限
        nlink_t       st_nlink;     //该文件的硬连接数目
        uid_t         st_uid;       //userID
        gid_t         st_gid;       //groupID
        dev_t         st_rdev;      //设备编号
        off_t         st_size;      //文件大小
        unsigned long st_blksize;   //文件系统的I/O缓冲区大小
        unsigned long st_blocks;    //块数
        time_t        st_atime;     //最后一次访问时间
        time_t        st_mtime;     //最后一次修改时间
        time_t        st_ctime;     //最后一次改变时间(指属性)
    };
    

    mystate代码实现如下

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        struct stat sb;
        if (argc != 2) {
            fprintf(stderr, "Usage: %s <pathname>
    ", argv[0]);
            exit(EXIT_FAILURE);
        }
        if (stat(argv[1], &sb) == -1) {
            perror("stat");
            exit(EXIT_FAILURE);
        }
        printf("File type:                ");
        switch (sb.st_mode & S_IFMT) {
            case S_IFBLK:   printf("block device
    ");
                break;
        case S_IFCHR:   printf("character device
    ");
                break;
        case S_IFDIR:   printf("directory
    ");
                break;
        case S_IFIFO:   printf("FIFO/pipe
    ");
                break;
        case S_IFLNK:   printf("symlink
    ");
                break;
        case S_IFREG:   printf("regular file
    ");
                break;
        case S_IFSOCK:  printf("socket
    ");
                break;
        default:        printf("unknown?
    ");
                break;
        }
        printf("I-node number:            %ld
    ", (long) sb.st_ino);
        printf("Mode:                     %lo (octal)
    ",(unsigned long) sb.st_mode);
        printf("Link count:               %ld
    ", (long) sb.st_nlink);
        printf("Ownership:                UID=%ld   GID=%ld
    ",(long) sb.st_uid, (long) sb.st_gid);
        printf("Preferred I/O block size: %ld bytes
    ",(long) sb.st_blksize);
        printf("File size:                %lld bytes
    ",(long long) sb.st_size);
        printf("Blocks allocated:         %lld
    ",(long long) sb.st_blocks);
        printf("Last status change:       %s", ctime(&sb.st_ctime));
        printf("Last file access:         %s", ctime(&sb.st_atime));
        printf("Last file modification:   %s", ctime(&sb.st_mtime));
        exit(EXIT_SUCCESS);
    }
    
  • 相关阅读:
    vc++编程之在程序中加入网址链接
    VC++编程之对话框贴图
    软考(软件设计师)注意事项(攻略)
    解决SQLite数据库中文乱码问题
    计算机专业中经典书籍(程序猿和大学生必读)
    VC++编程中为程序加入启动画面功能
    动态规划的详细解析(01背包问题)
    动态规划之深入灵魂的解读(非常好)
    UML类图详解
    团队冲刺——第四天
  • 原文地址:https://www.cnblogs.com/20175203mayuda/p/12103257.html
Copyright © 2011-2022 走看看