-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchmod.cxx
105 lines (95 loc) · 2.14 KB
/
chmod.cxx
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
/* -*- C++ -*- */
/*************************************************************************
* Copyright(c) 1995~2005 Masaharu Goto ([email protected])
*
* For the licensing terms see the file COPYING
*
************************************************************************/
// cint/chmod.cxx
// Change status
// *.exe : 777
// *.dll : 777
// directory : 777
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
void todir(const char* fullfname) {
char com[1000];
sprintf(com,"chmod 1777 %s",fullfname);
system(com);
printf("%s\n",com);
fprintf(stderr,"%s\n",com);
}
void toexe(const char* fullfname) {
char com[1000];
sprintf(com,"chmod 777 %s",fullfname);
system(com);
printf("%s\n",com);
fprintf(stderr,"%s\n",com);
}
void totext(const char* fullfname) {
char com[1000];
sprintf(com,"chmod 666 %s",fullfname);
system(com);
printf("%s\n",com);
fprintf(stderr,"%s\n",com);
}
void chstatus(const char* fullfname,const char* fname) {
char *p = strrchr(fullfname,'.');
if(p) {
if(strcmp(p,".exe")==0 ||
strcmp(p,".dll")==0 ||
strcmp(p,".bat")==0 ||
strcmp(p,".sh")==0) {
toexe(fullfname);
}
else {
totext(fullfname);
}
}
else {
totext(fullfname);
}
}
int scandir(const char* base,const char* dname) {
char fulldname[1000];
char fullfname[1000];
if(base) sprintf(fulldname,"%s/%s",base,dname);
else strcpy(fulldname,dname);
struct DIR *dir = opendir(fulldname);
struct dirent *d;
int s;
struct stat buf;
int flag=0;
while((d=readdir(dir))) {
++flag;
s=stat(d->d_name,&buf);
sprintf(fullfname,"%s/%s",fulldname,d->d_name);
#if 0
printf("%d %16b %25s %s\n" ,S_ISDIR(buf.st_mode) ,buf.st_mode
,fullfname ,d->d_name);
#endif
if(1||S_ISDIR(buf.st_mode)) {
if(d->d_name[0]!='.') {
if(scandir(fulldname,d->d_name)) {
todir(fullfname);
}
else {
chstatus(fullfname,d->d_name);
}
}
}
else {
chstatus(fullfname,d->d_name);
}
}
closedir(dir);
return(flag);
}
int main() {
scandir(0,getenv("CINTSYSDIR"));
return 0;
}