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

Side by Side Diff: util/file/fd_io.h

Issue 756653004: Add Logging{Read,Write}FD() and CheckedCloseFD() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | util/file/fd_io.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 12 matching lines...) Expand all
23 //! 23 //!
24 //! This function reads into \a buffer, stopping only when \a size bytes have 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 25 //! been read or when `read()` returns 0, indicating that end-of-file has been
26 //! reached. 26 //! reached.
27 //! 27 //!
28 //! \return The number of bytes read and placed into \a buffer, or `-1` on 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 29 //! error, with `errno` set appropriately. On error, a portion of \a fd may
30 //! have been read into \a buffer. 30 //! have been read into \a buffer.
31 //! 31 //!
32 //! \sa WriteFD 32 //! \sa WriteFD
33 //! \sa LoggingReadFD
33 //! \sa CheckedReadFD 34 //! \sa CheckedReadFD
34 //! \sa CheckedReadFDAtEOF 35 //! \sa CheckedReadFDAtEOF
35 ssize_t ReadFD(int fd, void* buffer, size_t size); 36 ssize_t ReadFD(int fd, void* buffer, size_t size);
36 37
37 //! \brief Wraps `write()`, retrying when interrupted or following a short 38 //! \brief Wraps `write()`, retrying when interrupted or following a short
38 //! write. 39 //! write.
39 //! 40 //!
40 //! This function writes to \a fd, stopping only when \a size bytes have been 41 //! This function writes to \a fd, stopping only when \a size bytes have been
41 //! written. 42 //! written.
42 //! 43 //!
43 //! \return The number of bytes written from \a buffer, or `-1` on error, with 44 //! \return The number of bytes written from \a buffer, or `-1` on error, with
44 //! `errno` set appropriately. On error, a portion of \a buffer may have 45 //! `errno` set appropriately. On error, a portion of \a buffer may have
45 //! been written to \a fd. 46 //! been written to \a fd.
46 //! 47 //!
47 //! \sa ReadFD 48 //! \sa ReadFD
49 //! \sa LoggingWriteFD
48 //! \sa CheckedWriteFD 50 //! \sa CheckedWriteFD
49 ssize_t WriteFD(int fd, const void* buffer, size_t size); 51 ssize_t WriteFD(int fd, const void* buffer, size_t size);
50 52
51 //! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read. 53 //! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read.
52 //! 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 //!
53 //! If \a size is out of the range of possible `read()` return values, if the 80 //! If \a size is out of the range of possible `read()` return values, if the
54 //! underlying ReadFD() fails, or if other than \a size bytes were read, this 81 //! underlying ReadFD() fails, or if other than \a size bytes were read, this
55 //! function causes execution to terminate without returning. 82 //! function causes execution to terminate without returning.
56 //! 83 //!
57 //! \sa CheckedWriteFD 84 //! \sa CheckedWriteFD
58 //! \sa ReadFD 85 //! \sa ReadFD
86 //! \sa LoggingReadFD
59 //! \sa CheckedReadFDAtEOF 87 //! \sa CheckedReadFDAtEOF
60 void CheckedReadFD(int fd, void* buffer, size_t size); 88 void CheckedReadFD(int fd, void* buffer, size_t size);
61 89
62 //! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written. 90 //! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written.
63 //! 91 //!
64 //! If \a size is out of the range of possible `write()` return values, if the 92 //! If \a size is out of the range of possible `write()` return values, if the
65 //! underlying WriteFD() fails, or if other than \a size bytes were written, 93 //! underlying WriteFD() fails, or if other than \a size bytes were written,
66 //! this function causes execution to terminate without returning. 94 //! this function causes execution to terminate without returning.
67 //! 95 //!
68 //! \sa CheckedReadFD 96 //! \sa CheckedReadFD
69 //! \sa WriteFD 97 //! \sa WriteFD
98 //! \sa LoggingWriteFD
70 void CheckedWriteFD(int fd, const void* buffer, size_t size); 99 void CheckedWriteFD(int fd, const void* buffer, size_t size);
71 100
72 //! \brief Wraps ReadFD(), ensuring that it indicates end-of-file. 101 //! \brief Wraps ReadFD(), ensuring that it indicates end-of-file.
73 //! 102 //!
74 //! Attempts to read a single byte from \a fd, expecting no data to be read. If 103 //! Attempts to read a single byte from \a fd, expecting no data to be read. If
75 //! the underlying ReadFD() fails, or if a byte actually is read, this function 104 //! the underlying ReadFD() fails, or if a byte actually is read, this function
76 //! causes execution to terminate without returning. 105 //! causes execution to terminate without returning.
77 //! 106 //!
78 //! \sa CheckedReadFD 107 //! \sa CheckedReadFD
79 //! \sa ReadFD 108 //! \sa ReadFD
80 void CheckedReadFDAtEOF(int fd); 109 void CheckedReadFDAtEOF(int fd);
81 110
82 //! \brief Wraps `close()`, logging an error if the operation fails. 111 //! \brief Wraps `close()`, logging an error if the operation fails.
83 //! 112 //!
84 //! \return On success, `true` is returned. On failure, an error is logged and 113 //! \return On success, `true` is returned. On failure, an error is logged and
85 //! `false` is returned. 114 //! `false` is returned.
86 bool LoggingCloseFD(int fd); 115 bool LoggingCloseFD(int fd);
87 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
88 } // namespace crashpad 123 } // namespace crashpad
89 124
90 #endif // CRASHPAD_UTIL_FILE_FD_IO_H_ 125 #endif // CRASHPAD_UTIL_FILE_FD_IO_H_
OLDNEW
« no previous file with comments | « no previous file | util/file/fd_io.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698