自定义mac的ll命令

#include<stdio.h>
#include<time.h>
#include<sys/types.h>
#include<dirent.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<.h>
 do_ls([]);
 dostat( *);
 show_file_info( *, stat *);
 mode_to_letters(,[]);
 * uid_to_name(uid_t);
 * gid_to_name(gid_t);

 main( argc, *argv[]){
    (argc==)
        do_ls();
    
        printf();
}

 do_ls( dirname[]){
    DIR *dir_ptr;        dirent *direntp;         ((dir_ptr=opendir(dirname))==)
        fprintf(stderr,,dirname);
    {
        ((direntp=readdir(dir_ptr))!=)
            dostat(direntp->d_name);
        closedir(dir_ptr);
    }
}

 dostat( *filename){
     stat info;
    (lstat(filename,&info)==-)
        perror();
    
        show_file_info(filename,&info);
}

 show_file_info( *filename, stat *info_p){
     modestr[];
    mode_to_letters(info_p->st_mode,modestr);
    printf(,modestr);
    printf(,()info_p->st_nlink);
    printf(,uid_to_name(info_p->st_uid));
    printf(,gid_to_name(info_p->st_gid));
    printf(,()info_p->st_size);
    time_t timelong=info_p->st_mtime;
     tm *htime=localtime(&timelong);
    printf(,htime->tm_year+,htime->tm_mon+,htime->tm_mday,htime->tm_hour,htime->tm_min);
    printf(,filename);
}


 mode_to_letters( mode, str[]){
    strcpy(str,);
    (S_ISDIR(mode))   str[]=;
    (S_ISCHR(mode))   str[]=;
    (S_ISBLK(mode))   str[]=;

    (mode & S_IRUSR)  str[]=;
    (mode & S_IWUSR)  str[]=;
    (mode & S_IXUSR)  str[]=;

    (mode & S_IRGRP)  str[]=;
    (mode & S_IWGRP)  str[]=;
    (mode & S_IXGRP)  str[]=;

    (mode & S_IROTH)  str[]=;
    (mode & S_IWOTH)  str[]=;
    (mode & S_IXOTH)  str[]=;
}

#include<pwd.h>      * uid_to_name(uid_t uid){
     passwd *pw_str;
      numstr[];
    ((pw_str=getpwuid(uid))==NULL){
        sprintf(numstr,,uid);                numstr;
    }
    
         pw_str->pw_name;
}

#include<grp.h>
 * gid_to_name(gid_t gid){
     group *grp_ptr;
      numstr[];
    ((grp_ptr=getgrgid(gid))==NULL){
        sprintf(numstr,,gid);
         numstr;
    }
    
         grp_ptr->gr_name;
}

190433_Ln84_1377701.png

转载于:https://my.oschina.net/u/1377701/blog/486516

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值