Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Author -XAgent Smith*/
- /*Date:Oct 21,2018*/
- /*Take singel argument Name of file or name of directory*/
- /*Listing Directeries files in
- [name]-[LNK]-[PERM]-[SIZ]-[DATE OF LAST MODIFICTION]or singel file info
- */
- #include<stdio.h>
- #include <time.h>
- #include <stdtool.c>
- #include<sys/fcntl.h>
- #include<sys/types.h>
- #include <dirent.h>
- #include<sys/stat.h>
- #include<unistd.h>
- /*******************************************/
- void print_info(char * dir,struct stat *stbuf)
- {
- printf("File:%s\t",dir);
- printf("LNK:%d\t",stbuf->st_nlink);
- printf((stbuf->st_mode&S_IFMT)==S_IFDIR?"d":"-");
- printf((stbuf->st_mode&S_IFBLK)?"b":"-");
- printf((stbuf->st_mode&S_IRUSR)?"r":"-");
- printf((stbuf->st_mode&S_IWUSR)?"w":"-");
- printf((stbuf->st_mode&S_IXUSR)?"x":"-");
- printf((stbuf->st_mode&S_IRGRP)?"r":"-");
- printf((stbuf->st_mode&S_IWGRP)?"w":"-");
- printf((stbuf->st_mode&S_IXGRP)?"x":"-");
- printf((stbuf->st_mode&S_IROTH)?"r":"-");
- printf((stbuf->st_mode&S_IWOTH)?"w":"-");
- printf((stbuf->st_mode&S_IXOTH)?"x":"-");
- printf("\tSize=[%lld]\t\t",stbuf->st_size);
- printf("%s",ctime(&stbuf->st_mtim));
- printf("\nFile %s symbolic link\n\n************************\n",(stbuf->st_mode&S_IFMT)==S_IFLNK?"is":"is not");
- return;
- }
- /*****************************************/
- /*lsdir:listing directory "dir"*/
- void lsdir(char *dir)
- {
- DIR *dfp;
- struct dirent *red;
- dfp=opendir(dir);
- while((red=readdir(dfp))!=NULL)
- {
- struct stat stbuf;
- if(strcmp(".",red->d_name)==0||strcmp("..",red->d_name)==0||red->d_ino==0)
- {
- continue;
- }
- stat(red->d_name,&stbuf);
- if((stbuf.st_mode&S_IFMT)==S_IFDIR)
- lsdir(red->d_name);
- print_info(red->d_name,&stbuf);
- }
- return;
- }
- /*
- *start of main
- *
- */
- int main(int argc,char **argv)
- {
- if(argc!=2)
- {
- errno=EINVAL;
- perror("ERROR");
- return 1;
- }
- else
- {
- struct stat stbuf;
- if(stat(*(++argv),&stbuf)<0)
- {
- perror(*argv);
- exit(-1);
- }
- if((stbuf.st_mode&S_IFMT)==S_IFDIR){
- lsdir(*argv);
- return 0;
- }
- else
- goto startx;
- }
- struct stat stbuf;
- startx:
- stat(*argv,&stbuf);
- print_info(*argv,&stbuf);
- return 0;
- }
Add Comment
Please, Sign In to add comment