Commit 31471e84 authored by reed@google.com's avatar reed@google.com

Change SkFileDescriptorStream to handle failure to open the file descriptor

(by initializing its length_ to 0), and to return the number of bytes skipped
if buffer==null, rather than returning the offset.
Review URL: http://codereview.chromium.org/8800017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113197 0039d316-1c4b-4281-b951-d872f2087c98
parent dc7c9d49
......@@ -244,6 +244,11 @@ class SkFileDescriptorStream : public SkStream {
memory_ = NULL;
offset_ = 0;
// this ensures that if we fail in the constructor, we will safely
// ignore all subsequent calls to read() because we will always trim
// the requested size down to 0
length_ = 0;
struct stat st;
if (fstat(fd, &st))
return;
......@@ -273,20 +278,12 @@ class SkFileDescriptorStream : public SkStream {
return length_;
}
if (!buffer) {
// This is a request to skip bytes.
if (offset_ + size < offset_)
return offset_;
offset_ += size;
if (offset_ > length_)
offset_ = length_;
return offset_;
}
size_t remaining = length_ - offset_;
if (size > remaining)
size = remaining;
memcpy(buffer, memory_ + offset_, size);
if (buffer)
memcpy(buffer, memory_ + offset_, size);
offset_ += size;
return size;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment