#实现ls的基础功能(用stat检索文件信息)

#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include  <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <pwd.h>
int main(int argc, char **argv[])
{
    int fa;
    struct stat myls;
    uid_t uid;

    if(stat(argv[1],&myls)<0)
    {
        printf("stat failed!\n");
        exit(-1);
    }
    if(S_ISREG(myls.st_mode))
    {
        printf("pu tong wen jian!");
    }
    if(S_ISDIR(myls.st_mode))
    {
        printf("d");
    }
    if(S_ISCHR(myls.st_mode))
    {
        printf("zi fu she bei");
    }
    if(S_ISBLK(myls.st_mode))
    {
        printf("kuai she bei");
    }
    printf(" ");
    if(myls.st_mode & S_IRUSR)//判断权限
    {
        printf("r ");
    }
    printf("%d ",myls.st_nlink);//硬链接

    printf("%s",ctime(&(myls.st_mtim)));//时间转换
    struct passwd * yuan=getpwuid(myls.st_uid);
    printf("%s",yuan->pw_name);

}
全部评论

相关推荐

点赞 评论 收藏
分享
LZHR:老哥你从投递简历测评完到一面中间隔了多久呀,我这边已经过了五天了仍显示简历筛选中是不是就是挂了
腾讯求职进展汇总
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务