Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <dirent.h>
- #include <sys/stat.h>
- #include <pwd.h>
- #include <grp.h>
- #include <time.h>
- #include <stdlib.h>
- char *prawa_dost(int tryb) {
- char *bufor;
- int i;
- bufor=(char *) malloc (19);
- for (i=9;i>=0;i--){
- if (((tryb >> i) % 2) == 1) {
- if ((i % 3) == 0)
- bufor[9 - i] = 'x';
- if ((i % 3) == 1)
- bufor[9 - i] = 'w';
- if ((i % 3) == 2)
- bufor[9 - i] = 'r';
- }
- else
- bufor[9 - i] = '-';
- }
- bufor[10] = 0;
- if (S_ISDIR (tryb)) {
- bufor[0] = 'd';
- return bufor;
- }
- if (S_ISBLK (tryb)) {
- bufor[0] = 'b';
- return bufor;
- }
- if (S_ISSOCK (tryb)) {
- bufor[0] = 's';
- return bufor;
- }
- if (S_ISCHR (tryb)) {
- bufor[0] = 'c';
- return bufor;
- }
- if (S_ISFIFO (tryb)) {
- bufor[0] = 'p';
- return bufor;
- }
- if (S_ISLNK (tryb)) {
- bufor[0] = 'l';
- return bufor;
- }
- bufor[0]='-'; // w przec. wypadku
- return bufor;
- }
- int main(int argc,char *argv[]){
- DIR *folder;
- struct dirent *wpis;
- struct stat info;
- struct tm *czas;
- struct passwd *pw;
- struct group *gr;
- if((folder = opendir("."))==NULL)
- printf("Blad odczytu katalogu");
- else
- {
- while((wpis=readdir(folder))!=NULL)
- {
- if(wpis->d_name[0] == '.') continue;
- lstat(wpis->d_name,&info);
- pw = getpwuid(info.st_uid);
- gr = getgrgid(info.st_gid);
- czas = gmtime(&info.st_mtime);
- printf("%s ",prawa_dost(info.st_mode));
- printf("% 10s ", pw->pw_name);
- printf("% 10s ", gr->gr_name);
- printf("%02d %02d %04d %02d:%02d",czas->tm_mday,((czas->tm_mon)+1),((czas->tm_year)+1900), czas->tm_hour+2, czas->tm_min);
- printf("% 8d ", (int)info.st_size);
- printf("%s ", wpis->d_name);
- puts("");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement