From a8a3832cec83b85254365cba12ff30c3b9adff05 Mon Sep 17 00:00:00 2001 From: li_junsong Date: Thu, 19 Oct 2023 19:55:15 +0800 Subject: [PATCH] =?UTF-8?q?Mkdirs=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_junsong --- interfaces/kits/rust/include/rust_file.h | 4 +++- interfaces/kits/rust/src/ffi.rs | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/rust/include/rust_file.h b/interfaces/kits/rust/include/rust_file.h index e6349905e..930fb9a73 100644 --- a/interfaces/kits/rust/include/rust_file.h +++ b/interfaces/kits/rust/include/rust_file.h @@ -104,12 +104,14 @@ long long int Lseek(int fd, long long offset, enum SeekPos pos); * @brief Creates a new directory at the given path. * @param path direction path. * @param mode creating ways. + * @retval 0 Created successfully. + * @retval -1 Creation failed. * @attention * 1.The input `path` must be in valid UTF-8 format. * 2.Errors are stored in errno. * @li rust_file.h:The file where the interface is located. */ -void Mkdirs(char* path, enum MakeDirectionMode mode); +int Mkdirs(char* path, enum MakeDirectionMode mode); /** * @ingroup rust diff --git a/interfaces/kits/rust/src/ffi.rs b/interfaces/kits/rust/src/ffi.rs index 8e2dde341..6cdc9540a 100644 --- a/interfaces/kits/rust/src/ffi.rs +++ b/interfaces/kits/rust/src/ffi.rs @@ -17,7 +17,7 @@ use crate::adapter::{ create_dir, error_control, get_parent, next_line, reader_iterator, seek, MakeDirectionMode, SeekPos, Str, }; -use libc::{c_char, c_longlong, c_void}; +use libc::{c_char, c_int, c_longlong, c_void}; use std::ffi::CString; use std::ptr::null_mut; @@ -55,10 +55,13 @@ pub extern "C" fn Lseek(fd: i32, offset: i64, pos: SeekPos) -> c_longlong { } #[no_mangle] -pub extern "C" fn Mkdirs(path: *const c_char, mode: MakeDirectionMode) { +pub extern "C" fn Mkdirs(path: *const c_char, mode: MakeDirectionMode) -> c_int { match create_dir(path, mode) { - Ok(_) => {} - Err(e) => unsafe { error_control(e) }, + Ok(_) => 0, + Err(e) => unsafe { + error_control(e); + -1 + }, } } -- Gitee