Cherry-pick a revert "sk_fgetsize to not use ftell."

Test: verified public sample documentation properly decodes
Bug: 62779478

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

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>
(cherry picked from commit e14a0aa7ea6a4494bbfae16864fab44c69b1f8d8)
diff --git a/src/ports/SkOSFile_posix.cpp b/src/ports/SkOSFile_posix.cpp
index 4002824..48b5b95 100644
--- a/src/ports/SkOSFile_posix.cpp
+++ b/src/ports/SkOSFile_posix.cpp
@@ -19,25 +19,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-size_t sk_fgetsize(FILE* f) {
-    int fd = fileno(f);
-    if (fd < 0) {
-        return 0;
-    }
-
-    struct stat status;
-    if (0 != fstat(fd, &status)) {
-        return 0;
-    }
-    if (!S_ISREG(status.st_mode)) {
-        return 0;
-    }
-    if (!SkTFitsIn<size_t>(status.st_size)) {
-        return 0;
-    }
-    return static_cast<size_t>(status.st_size);
-}
-
 bool sk_exists(const char *path, SkFILE_Flags flags) {
     int mode = F_OK;
     if (flags & kRead_SkFILE_Flag) {
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index e79d87f..68c2d3d 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -87,6 +87,24 @@
     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);
diff --git a/src/ports/SkOSFile_win.cpp b/src/ports/SkOSFile_win.cpp
index e66bcb8..7e194cf 100644
--- a/src/ports/SkOSFile_win.cpp
+++ b/src/ports/SkOSFile_win.cpp
@@ -17,27 +17,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 
-size_t sk_fgetsize(FILE* f) {
-    int fileno = sk_fileno(f);
-    if (fileno < 0) {
-        return 0;
-    }
-
-    HANDLE file = (HANDLE)_get_osfhandle(fileno);
-    if (INVALID_HANDLE_VALUE == file) {
-        return 0;
-    }
-
-    LARGE_INTEGER fileSize;
-    if (0 == GetFileSizeEx(file, &fileSize)) {
-        return 0;
-    }
-    if (!SkTFitsIn<size_t>(fileSize.QuadPart)) {
-        return 0;
-    }
-    return static_cast<size_t>(fileSize.QuadPart);
-}
-
 bool sk_exists(const char *path, SkFILE_Flags flags) {
     int mode = 0; // existence
     if (flags & kRead_SkFILE_Flag) {