Jed Estep | f1fc48c | 2015-12-15 16:04:53 -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 | |
| 17 | /* |
| 18 | * Provide a series of proxy functions for basic file accessors. |
| 19 | * The behavior of these functions can be changed to return different |
| 20 | * errors under a variety of conditions. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _UPDATER_OTA_IO_H_ |
| 24 | #define _UPDATER_OTA_IO_H_ |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <sys/stat.h> |
| 28 | |
Tao Bao | 6e02ea9 | 2016-11-17 11:24:07 -0800 | [diff] [blame] | 29 | #include <android-base/unique_fd.h> |
| 30 | |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 31 | #define OTAIO_CACHE_FNAME "/cache/saved.file" |
| 32 | |
| 33 | void ota_set_fault_files(); |
| 34 | |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 35 | int ota_open(const char* path, int oflags); |
| 36 | |
| 37 | int ota_open(const char* path, int oflags, mode_t mode); |
| 38 | |
| 39 | FILE* ota_fopen(const char* filename, const char* mode); |
| 40 | |
| 41 | int ota_close(int fd); |
| 42 | |
| 43 | int ota_fclose(FILE* fh); |
| 44 | |
| 45 | size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream); |
| 46 | |
| 47 | ssize_t ota_read(int fd, void* buf, size_t nbyte); |
| 48 | |
| 49 | size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream); |
| 50 | |
| 51 | ssize_t ota_write(int fd, const void* buf, size_t nbyte); |
| 52 | |
| 53 | int ota_fsync(int fd); |
| 54 | |
Tao Bao | 6e02ea9 | 2016-11-17 11:24:07 -0800 | [diff] [blame] | 55 | struct OtaCloser { |
| 56 | static void Close(int fd) { |
| 57 | ota_close(fd); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | using unique_fd = android::base::unique_fd_impl<OtaCloser>; |
| 62 | |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 63 | #endif |