-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.c
More file actions
73 lines (57 loc) · 1.17 KB
/
coverage.c
File metadata and controls
73 lines (57 loc) · 1.17 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
#include "coverage.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
static void copy(char* dst, const char* src)
{
if (!dst || !src)
return;
while (*src)
*dst++ = *src++;
*dst = '\0';
}
static int len(const char* str)
{
if (!str)
return 0;
int l = 1; // Accounts for \0 char
while (*str++)
l++;
return l;
}
static char* _cov_filename;
static FILE* cov_file;
static int* cov_counter;
void cov_filename(const char filename[])
{
if (_cov_filename != NULL)
free(_cov_filename);
_cov_filename = calloc(sizeof(char), len(filename));
copy(_cov_filename, filename);
}
void cov_start()
{
if (cov_file)
return;
cov_file = fopen(_cov_filename, "a");
time_t cur_time;
time(&cur_time);
char* start_time = ctime(&cur_time);
fprintf(cov_file, "START: %s", start_time);
cov_counter = calloc(1, sizeof(int));
}
void cov_hit(const char str[])
{
if (!cov_file)
return;
fprintf(cov_file, "%d: %s", *cov_counter, str);
(*cov_counter)++;
}
void cov_stop()
{
if (!cov_file)
return;
fclose(cov_file);
cov_file = NULL;
free(cov_counter);
}