forked from vmprof/vmprof-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.c
49 lines (44 loc) · 909 Bytes
/
machine.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
#include "machine.h"
#include "vmprof.h"
#include <stdio.h>
#ifdef VMPROF_UNIX
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#endif
int vmp_machine_bits(void)
{
return sizeof(void*)*8;
}
const char * vmp_machine_os_name(void)
{
#ifdef _WIN32
#ifdef _WIN64
return "win64";
#endif
return "win32";
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_MAC
return "mac os x";
#endif
#elif __linux__
return "linux";
#elif __FreeBSD__
return "freebsd";
#else
#error "Unknown compiler"
#endif
}
long vmp_fd_to_path(int fd, char * buffer, long buffer_len)
{
#ifdef VMPROF_LINUX
char proffs[24];
(void)snprintf(proffs, 24, "/proc/self/fd/%d", fd);
return readlink(proffs, buffer, buffer_len);
#elif defined(VMPROF_UNIX) && !defined(__FreeBSD__)
fcntl(fd, F_GETPATH, buffer);
return strlen(buffer);
#endif
return -1;
}