premiere fonction de stats optimisé a 5 et 5
This commit is contained in:
parent
f09be2ba12
commit
870450fe84
BIN
ping-report/ping-report
Executable file
BIN
ping-report/ping-report
Executable file
Binary file not shown.
BIN
ping-report/ping-report.db
Normal file
BIN
ping-report/ping-report.db
Normal file
Binary file not shown.
@ -32,9 +32,6 @@
|
||||
regex_t *p_reg;
|
||||
regmatch_t* pmatch;
|
||||
char* ping = NULL;
|
||||
int start;
|
||||
int end;
|
||||
size_t size_ping;
|
||||
|
||||
/* regex struct memory allocation */
|
||||
p_reg = (regex_t *) malloc(sizeof(*p_reg));
|
||||
@ -51,9 +48,9 @@
|
||||
|
||||
/* Construct regex to get ping from log file */
|
||||
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
|
||||
if(p_reg != NULL){
|
||||
//if(p_reg != NULL){
|
||||
free(p_reg);
|
||||
}
|
||||
//}
|
||||
(void) fclose(fd);
|
||||
return ping; /* NULL */
|
||||
}
|
||||
@ -67,6 +64,28 @@
|
||||
return ping; /* NULL */
|
||||
}
|
||||
|
||||
ping = find_ping(read_line, n, fd);
|
||||
|
||||
/* free allocated memory */
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
//if(read_line != NULL){
|
||||
//free(read_line);
|
||||
//}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
/* ping may be null, then it must mean that the ping request was lost */
|
||||
return ping;
|
||||
}
|
||||
|
||||
char* find_ping(char* read_line, size_t n, FILE* fd){
|
||||
int start;
|
||||
int end;
|
||||
size_t size_ping;
|
||||
char* ping2 = NULL;
|
||||
|
||||
/* Read file */
|
||||
while(getline(&read_line,&n,fd) != -1){
|
||||
|
||||
@ -84,8 +103,8 @@
|
||||
size_ping = (size_t) (end - start);
|
||||
|
||||
/* ping string memory allocation */
|
||||
ping = malloc(sizeof(char) * (size_ping+2));
|
||||
if(ping == NULL){
|
||||
ping2 = malloc(sizeof(char) * (size_ping+2));
|
||||
if(ping2 == NULL){
|
||||
free(read_line);
|
||||
read_line = NULL;
|
||||
n = 0;
|
||||
@ -93,9 +112,9 @@
|
||||
}
|
||||
|
||||
/* Create ping string */
|
||||
(void) strncpy(ping, &read_line[start], size_ping);
|
||||
ping[size_ping]='\n';
|
||||
ping[size_ping+1]='\0';
|
||||
(void) strncpy(ping2, &read_line[start], size_ping);
|
||||
ping2[size_ping]='\n';
|
||||
ping2[size_ping+1]='\0';
|
||||
|
||||
/* Free memory */
|
||||
free(read_line);
|
||||
@ -107,20 +126,8 @@
|
||||
free(read_line);
|
||||
read_line = NULL;
|
||||
n = 0;
|
||||
return ping2;
|
||||
}
|
||||
|
||||
/* free allocated memory */
|
||||
regfree(p_reg);
|
||||
free(p_reg);
|
||||
free(pmatch);
|
||||
if(read_line != NULL){
|
||||
free(read_line);
|
||||
}
|
||||
|
||||
(void) fclose(fd);
|
||||
|
||||
/* ping may be null, then it must mean that the ping request was lost */
|
||||
return ping;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user