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 //! File_ex provides interfaces for operating on file.
15 
16 #[cxx::bridge(namespace = "OHOS")]
17 /// Module file_ex::ffi. Includes interfaces which will call c++ counterparts
18 /// via FFI.
19 pub mod ffi {
20     #[allow(dead_code)]
21     unsafe extern "C++" {
22         include!("commonlibrary/c_utils/base/include/file_ex.h");
23         /// Read contents as a string from the specified file.
RustLoadStringFromFile(filePath: &String, content: &mut String) -> bool24         pub fn RustLoadStringFromFile(filePath: &String, content: &mut String) -> bool;
25 
26         /// Write contents of a string to the specified file.
RustSaveStringToFile(filePath: &String, content: &String, truncated: bool) -> bool27         pub fn RustSaveStringToFile(filePath: &String, content: &String, truncated: bool) -> bool;
28 
29         /// Read contents as a string from the file specified by its fd.
RustLoadStringFromFd(fd: i32, content: &mut String) -> bool30         pub fn RustLoadStringFromFd(fd: i32, content: &mut String) -> bool;
31 
32         /// Write contents of a string to the file specified by its fd.
RustSaveStringToFd(fd: i32, content: &String) -> bool33         pub fn RustSaveStringToFd(fd: i32, content: &String) -> bool;
34 
35         /// Read contents as a vector from the specified file.
RustLoadBufferFromFile(filePath: &String, content: &mut Vec<c_char>) -> bool36         pub fn RustLoadBufferFromFile(filePath: &String, content: &mut Vec<c_char>) -> bool;
37 
38         /// Write contents of a vector to the specified file.
RustSaveBufferToFile( filePath: &String, content: &Vec<c_char>, truncated: bool, ) -> bool39         pub fn RustSaveBufferToFile(
40             filePath: &String,
41             content: &Vec<c_char>,
42             truncated: bool,
43         ) -> bool;
44 
45         /// Check if the specified file exists.
RustFileExists(fileName: &String) -> bool46         pub fn RustFileExists(fileName: &String) -> bool;
47 
48         /// Check if the file contains specified contents in string.
RustStringExistsInFile( fileName: &String, subStr: &String, caseSensitive: bool, ) -> bool49         pub fn RustStringExistsInFile(
50             fileName: &String,
51             subStr: &String,
52             caseSensitive: bool,
53         ) -> bool;
54 
55         /// Get amount of the specified string in the file.
RustCountStrInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> i3256         pub fn RustCountStrInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> i32;
57     }
58 }
59