2015-02-03 01:31:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-03-16 17:08:46 +00:00
|
|
|
#ifndef BASE_FILE_H
|
|
|
|
#define BASE_FILE_H
|
2015-02-03 01:31:27 +00:00
|
|
|
|
2015-03-16 10:29:36 +00:00
|
|
|
#include <sys/stat.h>
|
2015-03-16 17:08:46 +00:00
|
|
|
#include <string>
|
2015-02-03 01:31:27 +00:00
|
|
|
|
2016-02-09 00:26:33 +00:00
|
|
|
#if !defined(_WIN32) && !defined(O_BINARY)
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2015-02-03 01:31:27 +00:00
|
|
|
namespace android {
|
2015-03-16 17:08:46 +00:00
|
|
|
namespace base {
|
2015-02-03 01:31:27 +00:00
|
|
|
|
2015-02-06 20:19:48 +00:00
|
|
|
bool ReadFdToString(int fd, std::string* content);
|
2015-02-03 01:31:27 +00:00
|
|
|
bool ReadFileToString(const std::string& path, std::string* content);
|
2015-02-06 20:19:48 +00:00
|
|
|
|
2015-02-03 01:31:27 +00:00
|
|
|
bool WriteStringToFile(const std::string& content, const std::string& path);
|
2015-02-06 20:19:48 +00:00
|
|
|
bool WriteStringToFd(const std::string& content, int fd);
|
2015-02-05 16:21:37 +00:00
|
|
|
|
|
|
|
#if !defined(_WIN32)
|
2015-02-04 21:19:13 +00:00
|
|
|
bool WriteStringToFile(const std::string& content, const std::string& path,
|
|
|
|
mode_t mode, uid_t owner, gid_t group);
|
2015-02-05 16:21:37 +00:00
|
|
|
#endif
|
2015-02-03 01:31:27 +00:00
|
|
|
|
2015-04-25 04:57:16 +00:00
|
|
|
bool ReadFully(int fd, void* data, size_t byte_count);
|
|
|
|
bool WriteFully(int fd, const void* data, size_t byte_count);
|
|
|
|
|
2016-01-30 01:25:54 +00:00
|
|
|
bool RemoveFileIfExists(const std::string& path, std::string* err = nullptr);
|
|
|
|
|
2015-03-16 17:08:46 +00:00
|
|
|
} // namespace base
|
|
|
|
} // namespace android
|
2015-02-03 01:31:27 +00:00
|
|
|
|
2015-03-16 17:08:46 +00:00
|
|
|
#endif // BASE_FILE_H
|