Skip to content

Commit 1f92cc1

Browse files
committed
Add safe errno
1 parent 5907a12 commit 1f92cc1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

libcc2rs/src/compat.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4+
use std::cell::RefCell;
45
use std::ffi::c_void;
6+
use std::rc::Rc;
7+
8+
use crate::rc::Ptr;
9+
use crate::{AsPointer, Value};
510

611
unsafe extern "C" {
712
#[cfg(target_os = "linux")]
@@ -43,3 +48,11 @@ pub unsafe fn malloc_usable_size(ptr: *mut c_void) -> usize {
4348
pub unsafe fn cpp2rust_errno() -> *mut i32 {
4449
unsafe { platform_errno_location() }
4550
}
51+
52+
thread_local! {
53+
static ERRNO: Value<i32> = Rc::new(RefCell::new(0));
54+
}
55+
56+
pub fn cpp2rust_errno() -> Ptr<i32> {
57+
ERRNO.with(AsPointer::as_pointer)
58+
}

0 commit comments

Comments
 (0)