Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: util/file/fd_io.h

Issue 577333002: Add and use CheckedReadFD(), CheckedWriteFD(), and CheckedReadFDAtEOF() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | util/file/fd_io.cc » ('j') | util/mac/process_reader_test.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/fd_io.h
diff --git a/util/file/fd_io.h b/util/file/fd_io.h
index 07f39b6d7587d5323112e5240ecb9352ff988b26..14481c93752c6fcec8e25566f37c5ea484017341 100644
--- a/util/file/fd_io.h
+++ b/util/file/fd_io.h
@@ -30,6 +30,8 @@ namespace crashpad {
//! have been read into \a buffer.
//!
//! \sa WriteFD
+//! \sa CheckedReadFD
+//! \sa CheckedReadFDAtEOF
ssize_t ReadFD(int fd, void* buffer, size_t size);
//! \brief Wraps `write()`, retrying when interrupted or following a short
@@ -43,8 +45,40 @@ ssize_t ReadFD(int fd, void* buffer, size_t size);
//! been written to \a fd.
//!
//! \sa ReadFD
+//! \sa CheckedWriteFD
ssize_t WriteFD(int fd, const void* buffer, size_t size);
+//! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read.
+//!
+//! If \a size is out of the range of possible `read()` return values, if the
+//! underlying ReadFD() fails, or if other than \a size bytes were read, this
+//! function causes execution to terminate without returning.
+//!
+//! \sa CheckedWriteFD
+//! \sa ReadFD
+//! \sa CheckedReadFDAtEOF
+void CheckedReadFD(int fd, void* buffer, size_t size);
+
+//! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written.
+//!
+//! If \a size is out of the range of possible `write()` return values, if the
+//! underlying WriteFD() fails, or if other than \a size bytes were written,
+//! this function causes execution to terminate without returning.
+//!
+//! \sa CheckedReadFD
+//! \sa WriteFD
+void CheckedWriteFD(int fd, const void* buffer, size_t size);
+
+//! \brief Wraps ReadFD(), ensuring that it indicates end-of-file.
+//!
+//! Attempts to read a single byte from \a fd, expecting no data to be read. If
+//! the underlying ReadFD() fails, or if a byte actually is read, this function
+//! causes execution to terminate without returning.
+//!
+//! \sa CheckedReadFD
+//! \sa ReadFD
+void CheckedReadFDAtEOF(int fd);
+
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_FD_IO_H_
« no previous file with comments | « no previous file | util/file/fd_io.cc » ('j') | util/mac/process_reader_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698