-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.c
More file actions
113 lines (109 loc) · 2.58 KB
/
Copy pathls.c
File metadata and controls
113 lines (109 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include"header.h"
char *uid_to_name(uid_t uid)
{
struct passwd *getpwuid(),*pw_ptr;
static char numstr[10];
if((pw_ptr=getpwuid(uid))==NULL)
{
sprintf(numstr,"%d",uid);
return numstr;
}
else
{
return pw_ptr->pw_name;
}
}
char *gid_to_name(gid_t gid)
{
struct group *getgrgid(),*grp_ptr;
static char numstr[10];
if((grp_ptr=getgrgid(gid))==NULL)
{
sprintf(numstr,"%d",gid);
return numstr;
}
else
{
return grp_ptr->gr_name;
}
}
void printdir(char *c,int f)
{
struct dirent *de;
DIR *dr=opendir(c);
if(dr==NULL)
{
printf("Could not open directory %s\n",c);
return ;
}
while((de=readdir(dr))!=NULL)
{
if(f)
{
if(de->d_name[0]!='.')
{
printf("%s\n",de->d_name);
}
}
else
{
printf("%s\n",de->d_name);
}
}
closedir(dr);
}
void lsl(char *c,int f)
{
struct stat thestat;
struct dirent *de;
struct passwd *tf;
struct group *gf;
DIR *dr=opendir(c);
if(dr==NULL)
{
printf("Could not open current directory\n");
return ;
}
while((de=readdir(dr))!=NULL)
{
if(f)
{
if(de->d_name[0]!='.')
{
stat(de->d_name,&thestat);
printf((thestat.st_mode & S_IRUSR) ? "\nr" : "\n-");
printf((thestat.st_mode & S_IWUSR) ? "w" : "-");
printf((thestat.st_mode & S_IXUSR) ? "x" : "-");
printf((thestat.st_mode & S_IRGRP) ? "r" : "-");
printf((thestat.st_mode & S_IWGRP) ? "w" : "-");
printf((thestat.st_mode & S_IXGRP) ? "x" : "-");
printf((thestat.st_mode & S_IROTH) ? "r" : "-");
printf((thestat.st_mode & S_IWOTH) ? "w" : "-");
printf((thestat.st_mode & S_IXOTH) ? "x" : "-");
char *ctime();
char *tmps=ctime(&thestat.st_mtime);
tmps[strlen(tmps)-1]=' ';
printf(" %d %s %s %d %s %s\n",(int)thestat.st_nlink,uid_to_name(thestat.st_uid),gid_to_name(thestat.st_gid),(int)thestat.st_size,tmps,de->d_name);
}
}
else
{
stat(de->d_name,&thestat);
printf((thestat.st_mode & S_IRUSR) ? "\nr" :"\n -");
printf((thestat.st_mode & S_IWUSR) ? "w" : "-");
printf((thestat.st_mode & S_IXUSR) ? "x" : "-");
printf((thestat.st_mode & S_IRGRP) ? "r" : "-");
printf((thestat.st_mode & S_IWGRP) ? "w" : "-");
printf((thestat.st_mode & S_IXGRP) ? "x" : "-");
printf((thestat.st_mode & S_IROTH) ? "r" : "-");
printf((thestat.st_mode & S_IWOTH) ? "w" : "-");
printf((thestat.st_mode & S_IXOTH) ? "x" : "-");
char *ctime();
char *tmps=ctime(&thestat.st_mtime);
tmps[strlen(tmps)-1]=' ';
printf(" %d %s %s %d %s %s\n",(int)thestat.st_nlink,uid_to_name(thestat.st_uid),gid_to_name(thestat.st_gid),(int)thestat.st_size,tmps,de->d_name);
}
}
printf("\n");
closedir(dr);
}