[Webkit-unassigned] [Bug 36938] Add basic FileSystem operations for FileReader/FileWriter support
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Tue Apr 6 15:36:38 PDT 2010
https://bugs.webkit.org/show_bug.cgi?id=36938
Jian Li <jianli at chromium.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #52673|review? |review-
Flag| |
--- Comment #12 from Jian Li <jianli at chromium.org> 2010-04-06 15:36:37 PST ---
(From update of attachment 52673)
Noticed another problem in read file logic plus a couple minor comment
suggestions. Almost there.
> +// Returns seeked offset if successful, -1 otherwise.
Probably need to rephrase a little bit, like:
// Returns the resulting offset from the beginning of the file if
successful, -1 otherwise.
> +long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
> +bool truncateFile(PlatformFileHandle handle, long long offset)
> +{
> + // ftruncate return 0 to indicate the success.
r/return/returns
> + return !ftruncate(handle, offset);
> +}
> +
> +int readFromFile(PlatformFileHandle handle, char* data, int length)
> +{
> + int totalBytesRead = 0;
> + while (totalBytesRead < length) {
> + int bytesRead = read(handle, data + totalBytesRead, static_cast<size_t>(length - totalBytesRead));
> + if (bytesRead <= 0 && errno != EINTR)
> + break;
If we encounter non-EINTR error and break out of the loop, we will return
totalBytesRead that is not -1.
In addition, we should not continue the reading if bytesRead >= 0.
I think the block can be reorganized like the following:
if (bytesRead >= 0) {
totalBytesRead += bytesRead;
break;
}
if (errno != EINTR)
return -1;
writeToFile could also do the similar thing for better readerability.
> + if (bytesRead > 0)
> + totalBytesRead += bytesRead;
> + }
> +
> + return totalBytesRead;
> +}
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list