| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 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 // http://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 CRASHPAD_UTIL_FILE_FD_IO_H_ | |
| 16 #define CRASHPAD_UTIL_FILE_FD_IO_H_ | |
| 17 | |
| 18 #include <sys/types.h> | |
| 19 | |
| 20 namespace crashpad { | |
| 21 | |
| 22 //! \brief Wraps `read()`, retrying when interrupted or following a short read. | |
| 23 //! | |
| 24 //! This function reads into \a buffer, stopping only when \a size bytes have | |
| 25 //! been read or when `read()` returns 0, indicating that end-of-file has been | |
| 26 //! reached. | |
| 27 //! | |
| 28 //! \return The number of bytes read and placed into \a buffer, or `-1` on | |
| 29 //! error, with `errno` set appropriately. On error, a portion of \a fd may | |
| 30 //! have been read into \a buffer. | |
| 31 //! | |
| 32 //! \sa WriteFD | |
| 33 //! \sa LoggingReadFD | |
| 34 //! \sa CheckedReadFD | |
| 35 //! \sa CheckedReadFDAtEOF | |
| 36 ssize_t ReadFD(int fd, void* buffer, size_t size); | |
| 37 | |
| 38 //! \brief Wraps `write()`, retrying when interrupted or following a short | |
| 39 //! write. | |
| 40 //! | |
| 41 //! This function writes to \a fd, stopping only when \a size bytes have been | |
| 42 //! written. | |
| 43 //! | |
| 44 //! \return The number of bytes written from \a buffer, or `-1` on error, with | |
| 45 //! `errno` set appropriately. On error, a portion of \a buffer may have | |
| 46 //! been written to \a fd. | |
| 47 //! | |
| 48 //! \sa ReadFD | |
| 49 //! \sa LoggingWriteFD | |
| 50 //! \sa CheckedWriteFD | |
| 51 ssize_t WriteFD(int fd, const void* buffer, size_t size); | |
| 52 | |
| 53 //! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read. | |
| 54 //! | |
| 55 //! \return `true` on success. If \a size is out of the range of possible | |
| 56 //! `read()` return values, if the underlying ReadFD() fails, or if other | |
| 57 //! than \a size bytes were read, this function logs a message and returns | |
| 58 //! `false`. | |
| 59 //! | |
| 60 //! \sa LoggingWriteFD | |
| 61 //! \sa ReadFD | |
| 62 //! \sa CheckedReadFD | |
| 63 //! \sa CheckedReadFDAtEOF | |
| 64 bool LoggingReadFD(int fd, void* buffer, size_t size); | |
| 65 | |
| 66 //! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written. | |
| 67 //! | |
| 68 //! \return `true` on success. If \a size is out of the range of possible | |
| 69 //! `write()` return values, if the underlying WriteFD() fails, or if other | |
| 70 //! than \a size bytes were written, this function logs a message and | |
| 71 //! returns `false`. | |
| 72 //! | |
| 73 //! \sa LoggingReadFD | |
| 74 //! \sa WriteFD | |
| 75 //! \sa CheckedWriteFD | |
| 76 bool LoggingWriteFD(int fd, const void* buffer, size_t size); | |
| 77 | |
| 78 //! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read. | |
| 79 //! | |
| 80 //! If \a size is out of the range of possible `read()` return values, if the | |
| 81 //! underlying ReadFD() fails, or if other than \a size bytes were read, this | |
| 82 //! function causes execution to terminate without returning. | |
| 83 //! | |
| 84 //! \sa CheckedWriteFD | |
| 85 //! \sa ReadFD | |
| 86 //! \sa LoggingReadFD | |
| 87 //! \sa CheckedReadFDAtEOF | |
| 88 void CheckedReadFD(int fd, void* buffer, size_t size); | |
| 89 | |
| 90 //! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written. | |
| 91 //! | |
| 92 //! If \a size is out of the range of possible `write()` return values, if the | |
| 93 //! underlying WriteFD() fails, or if other than \a size bytes were written, | |
| 94 //! this function causes execution to terminate without returning. | |
| 95 //! | |
| 96 //! \sa CheckedReadFD | |
| 97 //! \sa WriteFD | |
| 98 //! \sa LoggingWriteFD | |
| 99 void CheckedWriteFD(int fd, const void* buffer, size_t size); | |
| 100 | |
| 101 //! \brief Wraps ReadFD(), ensuring that it indicates end-of-file. | |
| 102 //! | |
| 103 //! Attempts to read a single byte from \a fd, expecting no data to be read. If | |
| 104 //! the underlying ReadFD() fails, or if a byte actually is read, this function | |
| 105 //! causes execution to terminate without returning. | |
| 106 //! | |
| 107 //! \sa CheckedReadFD | |
| 108 //! \sa ReadFD | |
| 109 void CheckedReadFDAtEOF(int fd); | |
| 110 | |
| 111 //! \brief Wraps `close()`, logging an error if the operation fails. | |
| 112 //! | |
| 113 //! \return On success, `true` is returned. On failure, an error is logged and | |
| 114 //! `false` is returned. | |
| 115 bool LoggingCloseFD(int fd); | |
| 116 | |
| 117 //! \brief Wraps `close()`, ensuring that it succeeds. | |
| 118 //! | |
| 119 //! If `close()` fails, this function causes execution to terminate without | |
| 120 //! returning. | |
| 121 void CheckedCloseFD(int fd); | |
| 122 | |
| 123 } // namespace crashpad | |
| 124 | |
| 125 #endif // CRASHPAD_UTIL_FILE_FD_IO_H_ | |
| OLD | NEW |