Skip to content

Commit

Permalink
Merge pull request #34 from zec/translate-path
Browse files Browse the repository at this point in the history
Addition of wrapper for path-translation utility function
  • Loading branch information
dmopalmer authored Dec 11, 2024
2 parents 0b3a617 + c9bc307 commit 1837c3a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ printf-wrap = { version = "^0.2", default-features = false }
psm = "^0.1.21"

[build-dependencies]
bindgen = "^0.59.1"
bindgen = { version = "^0.71.1", default-features = false, features = ["runtime"] }
cc = "^1.0"
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
.ctypes_prefix("::core::ffi")
.size_t_is_usize(true)
.generate_comments(false)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate cFS bindings");

Expand Down
1 change: 0 additions & 1 deletion n2o4/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion n2o4/README.md

This file was deleted.

38 changes: 38 additions & 0 deletions src/osal/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2024 The Pennsylvania State University and the project contributors.
// SPDX-License-Identifier: Apache-2.0

//! File system-level APIs.
use super::{I32Ext, OsalError};
use crate::sys::*;
use crate::utils::CStrBuf;

use core::ffi::{c_char, CStr};

/// The maximum allowed length of an OSAL path name,
/// including directory name, file name, and terminating NUL character.
///
/// Wraps `OS_MAX_PATH_LEN`.
#[doc(alias = "OS_MAX_PATH_LEN")]
pub const MAX_PATH_LEN: usize = OS_MAX_PATH_LEN as usize;

/// Translates an OSAL virtual file-system path
/// to a path name in the underlying system being
/// abstracted over.
///
/// Wraps `OS_TranslatePath`.
#[doc(alias = "OS_TranslatePath")]
#[inline]
pub fn translate_path<S: AsRef<CStr>>(
virtual_path: &S,
) -> Result<CStrBuf<MAX_PATH_LEN>, OsalError> {
let virtual_path: *const c_char = virtual_path.as_ref().as_ptr();
let mut local_path = [b'\0' as c_char; MAX_PATH_LEN];

// Safety: virtual_path is the start of a null-terminated string,
// local_path is long enough for all filenames OS_TranslatePath will output,
// and virtual_path and local_path both outlast the unsafe block.
unsafe { OS_TranslatePath(virtual_path, local_path.as_mut_ptr()) }.as_osal_status()?;

Ok(CStrBuf::new_into(local_path))
}
1 change: 1 addition & 0 deletions src/osal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) use error::I32Ext;

pub(crate) mod error;
pub mod file;
pub mod fs;
pub mod socket;
pub mod sync;
pub mod task;
Expand Down

0 comments on commit 1837c3a

Please sign in to comment.