Skip to content

Commit

Permalink
优化对C99的兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Apr 13, 2022
1 parent 0067a29 commit b24ad28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 6 additions & 4 deletions task/bt-psutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ void get_disk_io(struct disk_info_all *disk_io,int cycle) {

struct disk_info_all disk_io1 = {0,0,0,0,0,0,0,0};
struct disk_info_all disk_io2 = {0,0,0,0,0,0,0,0};
for(int i=0;i<disk_count;i++){
int i;
for(i=0;i<disk_count;i++){
char s = disk_info_list1[i].name[strlen(disk_info_list1[i].name) -1];
char e = disk_info_list1[i].name[strlen(disk_info_list1[i].name) -2];
if(e != '-' && (s > '0' && s < '9')) continue;
Expand All @@ -405,7 +406,7 @@ void get_disk_io(struct disk_info_all *disk_io,int cycle) {
sleep(cycle);

disk_count = get_disk_info(disk_info_list2);
for(int i=0;i<disk_count;i++){
for(i=0;i<disk_count;i++){
char s = disk_info_list2[i].name[strlen(disk_info_list2[i].name) -1];
char e = disk_info_list2[i].name[strlen(disk_info_list2[i].name) -2];
if(e != '-' && (s > '0' && s < '9')) continue;
Expand Down Expand Up @@ -506,7 +507,8 @@ void get_network_io(struct network_info_all *network_io,int cycle){

struct network_info_all network_io1 = {0.0,0.0,0.0,0.0,0,0,0,0,0,0,"",""};
struct network_info_all network_io2 = {0.0,0.0,0.0,0.0,0,0,0,0,0,0,"",""};
for(int i=0;i<network_count;i++){
int i;
for(i=0;i<network_count;i++){
network_io1.bytes_recv += network_info_list1[i].bytes_recv;
network_io1.packets_recv += network_info_list1[i].packets_recv;
network_io1.errin += network_info_list1[i].errin;
Expand All @@ -525,7 +527,7 @@ void get_network_io(struct network_info_all *network_io,int cycle){
network_io->sent_json[1] = '\0';
network_io->recv_json[1] = '\0';
char j_str[128];
for(int i=0;i<network_count;i++){
for(i=0;i<network_count;i++){
network_io2.bytes_recv += network_info_list2[i].bytes_recv;
network_io2.packets_recv += network_info_list2[i].packets_recv;
network_io2.errin += network_info_list2[i].errin;
Expand Down
12 changes: 8 additions & 4 deletions task/bt-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ void get_task_list(struct task_info *task_list){
int field_num = 3; // 字段数量
int ncolumn = nrow * field_num + field_num; // 计算实际数组长度
int n = 0;
for(int i=field_num;i<ncolumn;i++){
int i;
for(i=field_num;i<ncolumn;i++){
if(table_data[i] == NULL) continue;
int m = i % field_num; // 计算所属字段编号 0=id,1=type,2=execstr
switch(m){
Expand Down Expand Up @@ -111,7 +112,8 @@ void *start_task(void * arg){
get_task_list(task_list);

//遍历并执行任务
for(int i=0;i<20;i++){
int i;
for(i=0;i<20;i++){
if(task_list[i].id == 0) break;
//标记状态和开始时间
start = get_time();
Expand Down Expand Up @@ -793,7 +795,8 @@ int get_file_task_list(struct file_task_info *task_list){
int field_num = 4; // 字段数量
ncolumn = nrow * field_num + field_num; // 计算实际数组长度
int n = 0;
for(int i=field_num;i<ncolumn;i++){
int i;
for(i=field_num;i<ncolumn;i++){
if(table_data[i] == NULL) continue;
int m = i % field_num; // 计算所属字段编号 0=id,1=type,2=shell,3=other
switch(m){
Expand Down Expand Up @@ -850,7 +853,8 @@ void *start_file_task(void * arg){
struct file_task_info file_task_list[10];
int num = get_file_task_list(file_task_list);
if(num <= 0) continue;
for(int i=0;i<num;i++){
int i;
for(i=0;i<num;i++){
if(file_task_list[i].id[0] == '\0') break;
execute_file_task(file_task_list[i].id,file_task_list[i].type,file_task_list[i].shell,file_task_list[i].other);
}
Expand Down
6 changes: 4 additions & 2 deletions task/public.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ void get_string_md5(char *encrypt,char *result){
MD5Final(&md5s,decrypt);
char buff[2] = {0};
result[0] = '\0';
for(int i=0;i<16;i++){
int i;
for(i=0;i<16;i++){
sprintf(buff,"%02x",decrypt[i]);
strncat(result,buff,2);
}
Expand Down Expand Up @@ -453,7 +454,8 @@ void get_file_md5(char *file,char *result){
MD5Final(&md5s,decrypt);
char buff_str[2] = {0};
result[0] = '\0';
for(int i=0;i<16;i++){
int i;
for(i=0;i<16;i++){
sprintf(buff_str,"%02x",decrypt[i]);
strncat(result,buff_str,2);
}
Expand Down

0 comments on commit b24ad28

Please sign in to comment.