Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Elliott Hughes | 54c72aa | 2016-03-23 15:04:52 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_BASE_FILE_H |
| 18 | #define ANDROID_BASE_FILE_H |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 19 | |
Nicolas Geoffray | a7870d8 | 2015-03-16 10:29:36 +0000 | [diff] [blame] | 20 | #include <sys/stat.h> |
Dan Albert | c007bc3 | 2015-03-16 10:08:46 -0700 | [diff] [blame] | 21 | #include <string> |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 22 | |
Yabin Cui | 8e6f722 | 2016-02-08 16:26:33 -0800 | [diff] [blame] | 23 | #if !defined(_WIN32) && !defined(O_BINARY) |
| 24 | #define O_BINARY 0 |
| 25 | #endif |
| 26 | |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 27 | namespace android { |
Dan Albert | c007bc3 | 2015-03-16 10:08:46 -0700 | [diff] [blame] | 28 | namespace base { |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 30 | bool ReadFdToString(int fd, std::string* content); |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 31 | bool ReadFileToString(const std::string& path, std::string* content); |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 32 | |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 33 | bool WriteStringToFile(const std::string& content, const std::string& path); |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 34 | bool WriteStringToFd(const std::string& content, int fd); |
Elliott Hughes | d79801d | 2015-02-05 08:21:37 -0800 | [diff] [blame] | 35 | |
| 36 | #if !defined(_WIN32) |
Elliott Hughes | 202f024 | 2015-02-04 13:19:13 -0800 | [diff] [blame] | 37 | bool WriteStringToFile(const std::string& content, const std::string& path, |
| 38 | mode_t mode, uid_t owner, gid_t group); |
Elliott Hughes | d79801d | 2015-02-05 08:21:37 -0800 | [diff] [blame] | 39 | #endif |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 40 | |
Elliott Hughes | 56085ed | 2015-04-24 21:57:16 -0700 | [diff] [blame] | 41 | bool ReadFully(int fd, void* data, size_t byte_count); |
| 42 | bool WriteFully(int fd, const void* data, size_t byte_count); |
| 43 | |
Yabin Cui | b6e314a | 2016-01-29 17:25:54 -0800 | [diff] [blame] | 44 | bool RemoveFileIfExists(const std::string& path, std::string* err = nullptr); |
| 45 | |
Dan Albert | c007bc3 | 2015-03-16 10:08:46 -0700 | [diff] [blame] | 46 | } // namespace base |
| 47 | } // namespace android |
Elliott Hughes | dec12b2 | 2015-02-02 17:31:27 -0800 | [diff] [blame] | 48 | |
Elliott Hughes | 54c72aa | 2016-03-23 15:04:52 -0700 | [diff] [blame] | 49 | #endif // ANDROID_BASE_FILE_H |