aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkOSFile_stdio.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins <scroggo@google.com>2017-05-23 13:29:14 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-23 13:55:13 +0000
commit564ad05f065297658e691315993610e8055295c1 (patch)
tree07c6e726975a962e06550519cedcbb04cc2c25b7 /src/ports/SkOSFile_stdio.cpp
parent92de631edd3eb9b3430332d1f1d566e903ea2ea9 (diff)
Revert "sk_fgetsize to not use ftell."
This reverts commit eefa289a214ea3917e5e00554f231adb5ad6f712. Reason for revert: Causing failures in BitmapFactoryTest. b/38233042 Original change's description: > sk_fgetsize to not use ftell. > > The previous version of sk_fgetsize used ftell and fseek to compute > the size of a file. There are so many issues with this that it is called > out by securecoding.cert.org as FIO19-C as a thing not to do. We already > have correct code for computing the size of a file in the mmap code, so > use that instead. > > Change-Id: I1d771124989d0ec1523f6d858814ee563263213a > Reviewed-on: https://skia-review.googlesource.com/9860 > Reviewed-by: Leon Scroggins <scroggo@google.com> > Commit-Queue: Ben Wagner <bungeman@google.com> > TBR=bungeman@google.com,scroggo@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: Ie9392dde8747ae7c74ebfa00153705e316e841a2 Reviewed-on: https://skia-review.googlesource.com/17705 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/ports/SkOSFile_stdio.cpp')
-rw-r--r--src/ports/SkOSFile_stdio.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index e79d87fc89..68c2d3d4d7 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -87,6 +87,24 @@ FILE* sk_fopen(const char path[], SkFILE_Flags flags) {
return file;
}
+size_t sk_fgetsize(FILE* f) {
+ SkASSERT(f);
+
+ long curr = ftell(f); // remember where we are
+ if (curr < 0) {
+ return 0;
+ }
+
+ fseek(f, 0, SEEK_END); // go to the end
+ long size = ftell(f); // record the size
+ if (size < 0) {
+ size = 0;
+ }
+
+ fseek(f, curr, SEEK_SET); // go back to our prev location
+ return size;
+}
+
size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* f) {
SkASSERT(f);
return fwrite(buffer, 1, byteCount, f);