]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
rustify a silly function from rigctl
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 9 Aug 2023 16:54:30 +0000 (22:24 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 9 Aug 2023 17:19:47 +0000 (22:49 +0530)
rust/src/lib.rs
rust/src/rigctl.rs [new file with mode: 0644]

index 83d02690b5bc079cb73d1a3ceb539f8d244cb6e5..bc40ea065127a1a63541689243ee9a399cf80953 100644 (file)
@@ -1,4 +1,4 @@
-use libc::{size_t};
+mod rigctl;
 
 #[no_mangle]
 pub extern "C" fn add(left: usize, right: usize) -> usize {
diff --git a/rust/src/rigctl.rs b/rust/src/rigctl.rs
new file mode 100644 (file)
index 0000000..8aea534
--- /dev/null
@@ -0,0 +1,13 @@
+use std::os::fd::FromRawFd;
+use std::{fs::File, io::Write};
+use std::slice;
+use libc::{write, c_int, c_char};
+
+#[no_mangle]
+pub extern "C" fn send_resp(fd: c_int, msg: *const c_char) -> () {
+    let mut f: File = unsafe { File::from_raw_fd(fd) };
+    let cstr = unsafe { std::ffi::CStr::from_ptr(msg) };
+    let buf: &[u8] = cstr.to_bytes();
+    let _ = f.write_all(buf);
+    ()
+}