1 // Copyright 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SANDBOXED_API_UTIL_TEMP_FILE_H_ 16 #define SANDBOXED_API_UTIL_TEMP_FILE_H_ 17 18 #include <string> 19 #include <utility> 20 21 #include "absl/status/statusor.h" 22 #include "absl/strings/string_view.h" 23 24 namespace sapi { 25 26 // Creates a temporary file under a path starting with prefix. File is not 27 // unlinked and its path is returned together with an open fd. 28 absl::StatusOr<std::pair<std::string, int>> CreateNamedTempFile( 29 absl::string_view prefix); 30 31 // Creates a temporary file under a path starting with prefix. File is not 32 // unlinked and its path is returned. FD of the created file is closed just 33 // after creation. 34 absl::StatusOr<std::string> CreateNamedTempFileAndClose( 35 absl::string_view prefix); 36 37 // Creates a temporary directory under a path starting with prefix. 38 // Returns the path of the created directory. 39 absl::StatusOr<std::string> CreateTempDir(absl::string_view prefix); 40 41 } // namespace sapi 42 43 #endif // SANDBOXED_API_UTIL_TEMP_FILE_H_ 44