1 /* Copyright (c) 2023 Huawei Device Co., Ltd. 2 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * you may not use this file except in compliance with the License. 4 * You may obtain a copy of the License at 5 * 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 /*! 16 * File_ex provides interfaces for operating on file. 17 */ 18 19 #[cxx::bridge(namespace = "OHOS")] 20 /// Module file_ex::ffi. Includes interfaces which will call c++ counterparts via FFI. 21 pub mod ffi { 22 #[allow(dead_code)] 23 unsafe extern "C++" { 24 include!("commonlibrary/c_utils/base/include/file_ex.h"); 25 /// Read contents as a string from the specified file. RustLoadStringFromFile(filePath: &String, content: &mut String) -> bool26 pub fn RustLoadStringFromFile(filePath: &String, content: &mut String) -> bool; 27 28 /// Write contents of a string to the specified file. RustSaveStringToFile(filePath: &String, content: &String, truncated: bool) -> bool29 pub fn RustSaveStringToFile(filePath: &String, content: &String, truncated: bool) -> bool; 30 31 /// Read contents as a string from the file specified by its fd. RustLoadStringFromFd(fd: i32, content: &mut String) -> bool32 pub fn RustLoadStringFromFd(fd: i32, content: &mut String) -> bool; 33 34 /// Write contents of a string to the file specified by its fd. RustSaveStringToFd(fd: i32, content: &String) -> bool35 pub fn RustSaveStringToFd(fd: i32, content: &String) -> bool; 36 37 /// Read contents as a vector from the specified file. RustLoadBufferFromFile(filePath: &String, content: &mut Vec<c_char>) -> bool38 pub fn RustLoadBufferFromFile(filePath: &String, content: &mut Vec<c_char>) -> bool; 39 40 /// Write contents of a vector to the specified file. RustSaveBufferToFile(filePath: &String, content: &Vec<c_char>, truncated: bool) -> bool41 pub fn RustSaveBufferToFile(filePath: &String, content: &Vec<c_char>, truncated: bool) -> bool; 42 43 /// Check if the specified file exists. RustFileExists(fileName: &String) -> bool44 pub fn RustFileExists(fileName: &String) -> bool; 45 46 /// Check if the file contains specified contents in string. RustStringExistsInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> bool47 pub fn RustStringExistsInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> bool; 48 49 /// Get amount of the specified string in the file. RustCountStrInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> i3250 pub fn RustCountStrInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> i32; 51 } 52 } 53