-
Notifications
You must be signed in to change notification settings - Fork 21
/
rust_util.c
68 lines (60 loc) · 1.46 KB
/
rust_util.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
63
64
65
66
67
68
#include <fcntl.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
void get_cpu_time(int64_t *usr_secs, int64_t *usr_micros,
int64_t *sys_secs, int64_t *sys_micros)
{
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
*usr_secs = usage.ru_utime.tv_sec;
*usr_micros = usage.ru_utime.tv_usec;
*sys_secs = usage.ru_stime.tv_sec;
*sys_micros = usage.ru_stime.tv_usec;
}
extern void *g_rust_cli_conf_proto_ptr;
const void *get_global_cli_conf()
{
return g_rust_cli_conf_proto_ptr;
}
extern void *g_rust_failed_map;
void *get_mut_global_failure_map()
{
return g_rust_failed_map;
}
uint64_t g_rust_cli_download_count = 0;
void add_to_global_cli_download_count(uint64_t input)
{
g_rust_cli_download_count += input;
}
void reset_global_cli_download_count()
{
g_rust_cli_download_count = 0;
}
uint64_t get_global_cli_download_count()
{
return g_rust_cli_download_count;
}
int REPORTER_FD = -1;
char REPORTER_FNAME[129];
int try_open_reporter()
{
REPORTER_FD = open(REPORTER_FNAME, O_RDWR | O_NONBLOCK);
return REPORTER_FD;
}
void open_reporter(const char *fname)
{
strncpy(REPORTER_FNAME, fname, sizeof(REPORTER_FNAME) - 1);
try_open_reporter();
}
size_t write_reporter(uint8_t *buf, size_t len)
{
if (REPORTER_FD < 0 && try_open_reporter() < 0)
{
return 0;
}
ssize_t ret = write(REPORTER_FD, buf, len);
return (ret > 0) ? ret : 0;
}