1 /* 2 * Copyright 2017 Google LLC 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 #ifndef FCP_BASE_PLATFORM_H_ 18 #define FCP_BASE_PLATFORM_H_ 19 20 #include <string> 21 22 #include "absl/status/status.h" 23 #include "absl/status/statusor.h" 24 #include "absl/strings/cord.h" 25 #include "absl/strings/string_view.h" 26 27 // This file defines platform dependent utilities. 28 29 namespace fcp { 30 31 /** 32 * Concatenates two file path components using platform specific separator. 33 */ 34 std::string ConcatPath(absl::string_view path1, absl::string_view path2); 35 36 /** 37 * Strips a single platform specific path separator from the end of a path if 38 * it is present, returns the original path otherwise. 39 */ 40 absl::string_view StripTrailingPathSeparator(absl::string_view path); 41 42 /** 43 * Reads file content into string. 44 */ 45 absl::StatusOr<std::string> ReadFileToString(absl::string_view file_name); 46 47 /** 48 * Reads file content into absl::Cord. 49 */ 50 absl::StatusOr<absl::Cord> ReadFileToCord(absl::string_view file_name); 51 52 /** 53 * Writes string content into file. 54 */ 55 absl::Status WriteStringToFile(absl::string_view file_name, 56 absl::string_view content); 57 58 /** 59 * Writes cord content into file. 60 */ 61 absl::Status WriteCordToFile(absl::string_view file_name, 62 const absl::Cord& content); 63 64 /** 65 * Returns true if the file exists. 66 */ 67 bool FileExists(absl::string_view file_name); 68 69 /** 70 * Get absolute path given `relative_path` 71 */ 72 std::string GetDataPath(absl::string_view relative_path); 73 74 } // namespace fcp 75 76 #endif // FCP_BASE_PLATFORM_H_ 77