|
5 | 5 | // except according to those terms. |
6 | 6 |
|
7 | 7 | use crate::error::Result; |
8 | | -use crate::PyroscopeError; |
9 | 8 |
|
10 | 9 | use std::collections::HashMap; |
11 | 10 |
|
@@ -55,61 +54,3 @@ mod tests { |
55 | 54 | ) |
56 | 55 | } |
57 | 56 | } |
58 | | - |
59 | | -/// Wrapper for libc functions. |
60 | | -/// |
61 | | -/// Error wrapper for some libc functions used by the library. This only does |
62 | | -/// Error (-1 return) wrapping. Alternatively, the nix crate could be used |
63 | | -/// instead of expanding this wrappers (if more functions and types are used |
64 | | -/// from libc) |
65 | | -
|
66 | | -/// Error Wrapper for libc return. Only check for errors. |
67 | | -fn check_err<T: Ord + Default>(num: T) -> Result<T> { |
68 | | - if num < T::default() { |
69 | | - return Err(PyroscopeError::from(std::io::Error::last_os_error())); |
70 | | - } |
71 | | - Ok(num) |
72 | | -} |
73 | | - |
74 | | -/// libc::timerfd wrapper |
75 | | -pub fn timerfd_create(clockid: libc::clockid_t, clock_flags: libc::c_int) -> Result<i32> { |
76 | | - check_err(unsafe { libc::timerfd_create(clockid, clock_flags) }).map(|timer_fd| timer_fd as i32) |
77 | | -} |
78 | | - |
79 | | -/// libc::timerfd_settime wrapper |
80 | | -pub fn timerfd_settime( |
81 | | - timer_fd: i32, set_flags: libc::c_int, new_value: &mut libc::itimerspec, |
82 | | - old_value: &mut libc::itimerspec, |
83 | | -) -> Result<()> { |
84 | | - check_err(unsafe { libc::timerfd_settime(timer_fd, set_flags, new_value, old_value) })?; |
85 | | - Ok(()) |
86 | | -} |
87 | | - |
88 | | -/// libc::epoll_create1 wrapper |
89 | | -pub fn epoll_create1(epoll_flags: libc::c_int) -> Result<i32> { |
90 | | - check_err(unsafe { libc::epoll_create1(epoll_flags) }).map(|epoll_fd| epoll_fd as i32) |
91 | | -} |
92 | | - |
93 | | -/// libc::epoll_ctl wrapper |
94 | | -pub fn epoll_ctl(epoll_fd: i32, epoll_flags: libc::c_int, timer_fd: i32, event: &mut libc::epoll_event) -> Result<()> { |
95 | | - check_err(unsafe { |
96 | | - libc::epoll_ctl(epoll_fd, epoll_flags, timer_fd, event) |
97 | | - })?; |
98 | | - Ok(()) |
99 | | -} |
100 | | - |
101 | | -/// libc::epoll_wait wrapper |
102 | | -pub fn epoll_wait(epoll_fd: i32, events: *mut libc::epoll_event, maxevents: libc::c_int, timeout: libc::c_int) -> Result<()> { |
103 | | - check_err(unsafe { |
104 | | - libc::epoll_wait(epoll_fd, events, maxevents, timeout) |
105 | | - })?; |
106 | | - Ok(()) |
107 | | -} |
108 | | - |
109 | | -/// libc::read wrapper |
110 | | -pub fn read(timer_fd: i32, bufptr: *mut libc::c_void, count: libc::size_t) -> Result<()> { |
111 | | - check_err(unsafe { |
112 | | - libc::read(timer_fd, bufptr, count) |
113 | | - })?; |
114 | | - Ok(()) |
115 | | -} |
0 commit comments