1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <iterator>
20 #include <optional>
21 
22 namespace bluetooth {
23 namespace os {
24 
25 // Return true if |path| exists on disk
26 bool FileExists(const std::string& path);
27 
28 // Rename file from |from| to |to|
29 bool RenameFile(const std::string& from, const std::string& to);
30 
31 // Implement ability to read a whole file from |path| into a C++ string, return std::nullopt on failure
32 //
33 // Do not use this with large files
34 std::optional<std::string> ReadSmallFile(const std::string& path);
35 
36 // Implement ability to safely write to a file. This function is needed because of deficiencies in existing C++ file
37 // libraries, namely:
38 // - The ability to open and sync directories with storage media
39 // - The ability to block and sync file to storage media
40 // Return true on success, false on failure
41 bool WriteToFile(const std::string& path, const std::string& data);
42 
43 }  // namespace os
44 }  // namespace bluetooth