| 1 | #include "machine.h" |
| 2 | |
| 3 | #include "vmprof.h" |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #ifdef VMPROF_UNIX |
| 7 | #include <unistd.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <string.h> |
| 10 | #endif |
| 11 | |
| 12 | int vmp_machine_bits(void) |
| 13 | { |
| 14 | return sizeof(void*)*8; |
| 15 | } |
| 16 | |
| 17 | const char * vmp_machine_os_name(void) |
| 18 | { |
| 19 | #ifdef _WIN32 |
| 20 | #ifdef _WIN64 |
| 21 | return "win64"; |
| 22 | #endif |
| 23 | return "win32"; |
| 24 | #elif __APPLE__ |
| 25 | #include "TargetConditionals.h" |
| 26 | #if TARGET_OS_MAC |
| 27 | return "mac os x"; |
| 28 | #endif |
| 29 | #elif __linux__ |
| 30 | return "linux"; |
| 31 | #elif __FreeBSD__ |
| 32 | return "freebsd"; |
| 33 | #else |
| 34 | #error "Unknown compiler" |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | long vmp_fd_to_path(int fd, char * buffer, long buffer_len) |
| 39 | { |
| 40 | #ifdef VMPROF_LINUX |
| 41 | char proffs[24]; |
| 42 | (void)snprintf(proffs, 24, "/proc/self/fd/%d", fd); |
| 43 | return readlink(proffs, buffer, buffer_len); |
| 44 | #elif defined(VMPROF_UNIX) && !defined(__FreeBSD__) |
| 45 | fcntl(fd, F_GETPATH, buffer); |
| 46 | return strlen(buffer); |
| 47 | #endif |
| 48 | return -1; |
| 49 | } |