forked from adipinto/offline-sip-cracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.c
62 lines (56 loc) · 1.26 KB
/
globals.c
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
#include "globals.h"
#include "memory.h"
/*
* This function calculate the actual time in special formatted string.
* On error, will be returned NULL value.
*/
void print_actual_time() {
time_t timer;
char *buffer;
struct tm* tm_info;
// Allocate buffer
buffer = allocate_memory(25);
time(&timer);
tm_info = localtime(&timer);
// Get formatted time string
if (strftime(buffer, 25, "%H:%M:%S - %d/%m/%Y", tm_info) != 0) {
printf("%s\n", buffer);
// Release resource allocated
free(buffer);
} else {
printf("[time_calculation_error");
}
}
/*
* Convert each characters in 'str' into uppercase value.
*/
char* touppercase(char *str) {
if (str == NULL)
return "";
while (*str != '\0')
if (islower(*str))
*str = toupper(*str);
return str;
}
/*
* The following two functions, print out formatted time
*/
void print_start_time() {
printf("[*] Started at ");
print_actual_time();
}
void print_end_time() {
// Disable debug mode, prevent unformatted print of time.
DEBUG = FALSE;
printf("[*] Terminated at ");
print_actual_time();
}
/*
* This function before exit, print the actual time.
*/
void c_exit(int exit_code) {
// Print actual time
print_end_time();
// Exit with specified code.
exit(exit_code);
}