13f4cbf05Sopenharmony_ci// Copyright (c) 2023 Huawei Device Co., Ltd.
23f4cbf05Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
33f4cbf05Sopenharmony_ci// you may not use this file except in compliance with the License.
43f4cbf05Sopenharmony_ci// You may obtain a copy of the License at
53f4cbf05Sopenharmony_ci//
63f4cbf05Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
73f4cbf05Sopenharmony_ci//
83f4cbf05Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
93f4cbf05Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
103f4cbf05Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113f4cbf05Sopenharmony_ci// See the License for the specific language governing permissions and
123f4cbf05Sopenharmony_ci// limitations under the License.
133f4cbf05Sopenharmony_ci
143f4cbf05Sopenharmony_ci//! File_ex provides interfaces for operating on file.
153f4cbf05Sopenharmony_ci
163f4cbf05Sopenharmony_ci#[cxx::bridge(namespace = "OHOS")]
173f4cbf05Sopenharmony_ci/// Module file_ex::ffi. Includes interfaces which will call c++ counterparts
183f4cbf05Sopenharmony_ci/// via FFI.
193f4cbf05Sopenharmony_cipub mod ffi {
203f4cbf05Sopenharmony_ci    #[allow(dead_code)]
213f4cbf05Sopenharmony_ci    unsafe extern "C++" {
223f4cbf05Sopenharmony_ci        include!("commonlibrary/c_utils/base/include/file_ex.h");
233f4cbf05Sopenharmony_ci        /// Read contents as a string from the specified file.
243f4cbf05Sopenharmony_ci        pub fn RustLoadStringFromFile(filePath: &String, content: &mut String) -> bool;
253f4cbf05Sopenharmony_ci
263f4cbf05Sopenharmony_ci        /// Write contents of a string to the specified file.
273f4cbf05Sopenharmony_ci        pub fn RustSaveStringToFile(filePath: &String, content: &String, truncated: bool) -> bool;
283f4cbf05Sopenharmony_ci
293f4cbf05Sopenharmony_ci        /// Read contents as a string from the file specified by its fd.
303f4cbf05Sopenharmony_ci        pub fn RustLoadStringFromFd(fd: i32, content: &mut String) -> bool;
313f4cbf05Sopenharmony_ci
323f4cbf05Sopenharmony_ci        /// Write contents of a string to the file specified by its fd.
333f4cbf05Sopenharmony_ci        pub fn RustSaveStringToFd(fd: i32, content: &String) -> bool;
343f4cbf05Sopenharmony_ci
353f4cbf05Sopenharmony_ci        /// Read contents as a vector from the specified file.
363f4cbf05Sopenharmony_ci        pub fn RustLoadBufferFromFile(filePath: &String, content: &mut Vec<c_char>) -> bool;
373f4cbf05Sopenharmony_ci
383f4cbf05Sopenharmony_ci        /// Write contents of a vector to the specified file.
393f4cbf05Sopenharmony_ci        pub fn RustSaveBufferToFile(
403f4cbf05Sopenharmony_ci            filePath: &String,
413f4cbf05Sopenharmony_ci            content: &Vec<c_char>,
423f4cbf05Sopenharmony_ci            truncated: bool,
433f4cbf05Sopenharmony_ci        ) -> bool;
443f4cbf05Sopenharmony_ci
453f4cbf05Sopenharmony_ci        /// Check if the specified file exists.
463f4cbf05Sopenharmony_ci        pub fn RustFileExists(fileName: &String) -> bool;
473f4cbf05Sopenharmony_ci
483f4cbf05Sopenharmony_ci        /// Check if the file contains specified contents in string.
493f4cbf05Sopenharmony_ci        pub fn RustStringExistsInFile(
503f4cbf05Sopenharmony_ci            fileName: &String,
513f4cbf05Sopenharmony_ci            subStr: &String,
523f4cbf05Sopenharmony_ci            caseSensitive: bool,
533f4cbf05Sopenharmony_ci        ) -> bool;
543f4cbf05Sopenharmony_ci
553f4cbf05Sopenharmony_ci        /// Get amount of the specified string in the file.
563f4cbf05Sopenharmony_ci        pub fn RustCountStrInFile(fileName: &String, subStr: &String, caseSensitive: bool) -> i32;
573f4cbf05Sopenharmony_ci    }
583f4cbf05Sopenharmony_ci}
59