summaryrefslogtreecommitdiffstats
path: root/chrome_frame/utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome_frame/utils.cc')
-rw-r--r--chrome_frame/utils.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc
index b375dcc..735ec6f 100644
--- a/chrome_frame/utils.cc
+++ b/chrome_frame/utils.cc
@@ -1191,3 +1191,25 @@ std::string Bscf2Str(DWORD flags) {
return s;
#undef ADD_BSCF_FLAG
}
+
+// Reads data from a stream into a string.
+HRESULT ReadStream(IStream* stream, size_t size, std::string* data) {
+ DCHECK(stream);
+ DCHECK(data);
+
+ DWORD read = 0;
+ HRESULT hr = stream->Read(WriteInto(data, size + 1), size, &read);
+ DCHECK(hr == S_OK || hr == S_FALSE || hr == E_PENDING);
+ if (read) {
+ data->erase(read);
+ DCHECK_EQ(read, data->length());
+ } else {
+ data->clear();
+ // Return S_FALSE if the underlying stream returned S_OK and zero bytes.
+ if (hr == S_OK)
+ hr = S_FALSE;
+ }
+
+ return hr;
+}
+