We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 97a8048 commit 19242b5Copy full SHA for 19242b5
src/fun_c.rs
@@ -1,12 +1,23 @@
1
#[no_mangle]
2
pub extern "C" fn write_file(file_name: *const libc::c_char, buf: *const u8, buf_len: u32) -> bool {
3
use std::ffi;
4
+ use std::fs;
5
use std::fs::File;
6
use std::io::prelude::*;
7
use std::slice;
8
9
unsafe {
10
if let Ok(file_name) = ffi::CStr::from_ptr(file_name).to_str() {
11
+ use std::path::Path;
12
+ let path = Path::new(file_name);
13
+ if let Some(parent) = path.parent() {
14
+ if !parent.as_os_str().is_empty() {
15
+ if let Err(e) = fs::create_dir_all(parent) {
16
+ error!("create dir fail: {}", e);
17
+ return false;
18
+ }
19
20
21
if let Ok(mut f) = File::create(file_name) {
22
let arr = slice::from_raw_parts(buf, buf_len as usize);
23
match f.write_all(arr) {
0 commit comments