premiere fonction de stats optimisé a 5 et 5

This commit is contained in:
Dylan LANDRIN 2024-09-17 12:14:25 +02:00
parent f09be2ba12
commit 870450fe84
3 changed files with 30 additions and 23 deletions

BIN
ping-report/ping-report Executable file

Binary file not shown.

BIN
ping-report/ping-report.db Normal file

Binary file not shown.

View File

@ -32,9 +32,6 @@
regex_t *p_reg; regex_t *p_reg;
regmatch_t* pmatch; regmatch_t* pmatch;
char* ping = NULL; char* ping = NULL;
int start;
int end;
size_t size_ping;
/* regex struct memory allocation */ /* regex struct memory allocation */
p_reg = (regex_t *) malloc(sizeof(*p_reg)); p_reg = (regex_t *) malloc(sizeof(*p_reg));
@ -51,9 +48,9 @@
/* Construct regex to get ping from log file */ /* Construct regex to get ping from log file */
if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){ if(regcomp(p_reg,"time=(.*) ms",REG_EXTENDED) != 0){
if(p_reg != NULL){ //if(p_reg != NULL){
free(p_reg); free(p_reg);
} //}
(void) fclose(fd); (void) fclose(fd);
return ping; /* NULL */ return ping; /* NULL */
} }
@ -67,6 +64,28 @@
return ping; /* NULL */ 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 */ /* Read file */
while(getline(&read_line,&n,fd) != -1){ while(getline(&read_line,&n,fd) != -1){
@ -84,8 +103,8 @@
size_ping = (size_t) (end - start); size_ping = (size_t) (end - start);
/* ping string memory allocation */ /* ping string memory allocation */
ping = malloc(sizeof(char) * (size_ping+2)); ping2 = malloc(sizeof(char) * (size_ping+2));
if(ping == NULL){ if(ping2 == NULL){
free(read_line); free(read_line);
read_line = NULL; read_line = NULL;
n = 0; n = 0;
@ -93,9 +112,9 @@
} }
/* Create ping string */ /* Create ping string */
(void) strncpy(ping, &read_line[start], size_ping); (void) strncpy(ping2, &read_line[start], size_ping);
ping[size_ping]='\n'; ping2[size_ping]='\n';
ping[size_ping+1]='\0'; ping2[size_ping+1]='\0';
/* Free memory */ /* Free memory */
free(read_line); free(read_line);
@ -107,20 +126,8 @@
free(read_line); free(read_line);
read_line = NULL; read_line = NULL;
n = 0; 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;
} }
/* /*