免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
簡單,不易于使用的myls
    main.c 文件  1 #include <stdio.h>  2 #include <string.h>  3 #include <stdlib.h>  4 #include <glob.h>  5 #include <error.h>  6 #include <dirent.h>  7 #include "myls.h"  8   9 void stat_attbute(struct stat *buf); 10  int is_not_dir(char *name); 11  12 int main(int argc, char **argv) 13 { 14     int ch = 0; 15     struct stat buf; 16     char path[1024]; 17     DIR *dp = NULL; 18     struct dirent * ret; 19  20     char *optstring = "-lia"; 21  22     while(ch != -1) 23     { 24         ch = getopt(argc, argv, optstring); 25  26         if(argv[1] == NULL && ch == -1) 27         { 28                 ch = 'm'; 29                 strcpy(path, "."); 30         } 31         else 32             if(ch == 1) 33  34                 strcpy(path,argv[optind - 1]); 35  36         dp = opendir(path); 37  38  39         switch(ch) 40         { 41  42             case 'l': 43                 while(1) 44                 { 45                     ret = readdir(dp); 46                     if(ret == NULL) 47                     { 48                         if(ret) 49                         { 50                             perror("readdir()"); 51                             closedir(dp); 52                         } 53                         break; 54                     } 55                     if(!is_not_dir(ret->d_name)) 56                         continue; 57  58                     if(stat(ret->d_name, &buf)) 59                     { 60                         perror("stat()"); 61                         closedir(dp); 62                     } 63                     stat_attbute(&buf); 64                     printf("%s\n",ret->d_name); 65                 } 66                 break; 67             case 'i': 68                 while(1) 69                 { 70                     ret = readdir(dp); 71                     if(ret == NULL) 72                     { 73                         if(ret) 74                         { 75                             perror("readdir()"); 76                             closedir(dp); 77                         } 78                         break; 79                     } 80                      if(!is_not_dir(ret->d_name)) 81                          continue; 82                     if(stat(ret->d_name, &buf)) 83                     { 84                         perror("stat()"); 85                         closedir(dp); 86                         return -1; 87                     } 88                     stat_ino(&buf); 89                     printf("%s\n",ret->d_name); 90                 } 91                 break; 92  93             case 'a': 94                 while(1) 95                 { 96                     ret = readdir(dp); 97                     if(ret == NULL) 98                     { 99                         if(ret)100                         {101                             perror("readdir()");102                             closedir(dp);103                         }104                         break;105                     }106                     printf("s  ",ret->d_name);107                 }108                     break;109 110             case 'm':111                 while(1)112                 {113                     ret = readdir(dp);114                     if(ret == NULL)115                     {116                         if(ret)117                         {118                             perror("readdir()");119                             closedir(dp);120                         }121                         break;122                     }123                      if(!is_not_dir(ret->d_name))124                          continue;125                     printf("  %s",ret->d_name);126                 }127                 ch = -1;128                 break;129 130             case '?':131                 printf("沒有此選項%s\n",argv[optind - 1]);132                 break;133             default:134                 break;135         }136 137     }138 139 140 141     return 0;142 }143 144 void stat_attbute(struct stat *buf)145 {146 147     stat_file(buf);//文件類型148     stat_mode(buf);//文件權(quán)限149     stat_link(buf);//hard link150     stat_usr(buf);//文件用戶名151     stat_gup(buf);//文件組用戶名152     stat_byte(buf);//文件字節(jié)大小153     stat_time(buf);//文件最后保存時間154 155 }156 157 int is_not_dir(char *name)158 {159 160     if(name[0] == '.')161         return 0;162 163     return 1;164 }165 166                myls.h文件  1 #ifndef __MYLS_H  2 #define __MYLS_H  3 #include <sys/types.h>  4 #include <sys/stat.h>  5 #include <fcntl.h>  6 #include <unistd.h>  7 #include <time.h>  8 #include <grp.h>  9 #include <pwd.h> 10 void stat_file(struct stat *buf);//文件類型 11 void stat_mode(struct stat *buf);//文件權(quán)限 12 void stat_link(struct stat *buf);//hard link 13 void stat_usr(struct stat *buf);//文件用戶名 14 void stat_gup(struct stat *buf);//文件組用戶名 15 void stat_byte(struct stat *buf);//文件字節(jié)大小 16 void stat_time(struct stat *buf);//文件最后保存時間 17 void stat_ino(struct stat *buf);//ino 18 #endif                        myls.c文件  1 #include <stdio.h>  2 #include "myls.h"  3 void stat_file(struct stat *buf)//文件類型  4 {  5   6     switch(buf->st_mode & S_IFMT)  7     {  8         case S_IFIFO :  9             printf("p"); 10             break; 11  12         case S_IFCHR : 13             printf("c"); 14             break; 15  16         case S_IFDIR : 17             printf("d"); 18             break; 19  20         case S_IFBLK : 21             printf("b"); 22             break; 23         case S_IFREG : 24             printf("-"); 25             break; 26         case S_IFLNK : 27             printf("l"); 28             break; 29         case S_IFSOCK : 30             printf("s"); 31             break; 32     } 33  34  35 } 36 void stat_mode(struct stat *buf)//文件權(quán)限 37 { 38     if(buf->st_mode & S_IRUSR) 39         printf("r"); 40     else 41         putchar('-'); 42  43     if(buf->st_mode & S_IWUSR) 44         printf("w"); 45     else 46         putchar('-'); 47  48     if(buf->st_mode & S_IXUSR) 49         printf("x"); 50     else 51         putchar('-'); 52  53     if(buf->st_mode & S_IRGRP) 54         printf("r"); 55     else 56         putchar('-'); 57  58     if(buf->st_mode & S_IWGRP) 59         printf("w"); 60     else 61         putchar('-'); 62  63     if(buf->st_mode & S_IXGRP) 64         printf("x"); 65     else 66         putchar('-'); 67  68     if(buf->st_mode & S_IROTH) 69         printf("r"); 70     else 71         putchar('-'); 72  73     if(buf->st_mode & S_IWOTH) 74         printf("w"); 75     else 76         putchar('-'); 77  78     if(buf->st_mode & S_IWOTH) 79         printf("x"); 80     else 81         putchar('-'); 82         putchar(' '); 83 } 84 void stat_link(struct stat *buf)//hard link 85 { 86     printf("%ld ", buf->st_nlink); 87 } 88 void stat_usr(struct stat *buf)//文件用戶名 89 { 90     struct passwd *pwd = NULL; 91  92     pwd = getpwuid(buf->st_uid); 93  94     printf("%s ",pwd->pw_name); 95  96 } 97 void stat_gup(struct stat *buf)//文件組用戶名 98 { 99     struct group *gnam = NULL;100 101     gnam = getgrgid(buf->st_gid);102 103     printf("%s ",gnam->gr_name);104 105 }106 void stat_byte(struct stat *buf)//文件字節(jié)大小107 {108     printf("%ld ",buf->st_size);109 110 }111 void stat_time(struct stat *buf)//文件最后保存時間112 {113     struct tm *times;114     char buff[1024];115 116     times = localtime(&buf->st_mtim.tv_sec);117 118     strftime(buff, 1024, "%m月  %d %H:%M", times);119     printf("%s ",buff);120 }121 void stat_ino(struct stat *buf)//ino122 {123     printf("%ld  ",buf->st_ino);124 }~       

 


本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Linux i2c子系統(tǒng)應(yīng)用之Linux ARM嵌入式i2c通信(設(shè)備驅(qū)動完成i2c從設(shè)備寄存器的配...
《RTC — RTC相關(guān)操作以及如何同步系統(tǒng)時間》
分享幾個實用的嵌入式C程序!
【轉(zhuǎn)】C語言編的unix病毒
★C語言試題及答案
在gethostbyname
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服