#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;
}