diff options
author | halcanary <halcanary@google.com> | 2015-11-20 13:47:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-20 13:47:49 -0800 |
commit | d76be9c79baa1530d3dc95c58022e83607a1bb2a (patch) | |
tree | ebab3adf39a9eee73f1284517eba04d1ca82fa47 | |
parent | 90ba095c459e38581353073826785074b5953b8c (diff) |
Eliminate SkFILE: it always is the same as FILE.
Review URL: https://codereview.chromium.org/1467533003
-rw-r--r-- | include/core/SkData.h | 13 | ||||
-rw-r--r-- | include/core/SkOSFile.h | 34 | ||||
-rw-r--r-- | include/core/SkStream.h | 6 | ||||
-rw-r--r-- | src/core/SkData.cpp | 4 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkOSFile_posix.cpp | 12 | ||||
-rw-r--r-- | src/ports/SkOSFile_stdio.cpp | 62 | ||||
-rw-r--r-- | src/ports/SkOSFile_win.cpp | 8 | ||||
-rw-r--r-- | src/utils/SkRTConf.cpp | 4 | ||||
-rw-r--r-- | src/utils/SkWhitelistTypefaces.cpp | 2 | ||||
-rw-r--r-- | tests/DataRefTest.cpp | 2 | ||||
-rw-r--r-- | tests/PathOpsSkpClipTest.cpp | 2 | ||||
-rw-r--r-- | tools/chrome_fuzz.cpp | 2 |
13 files changed, 77 insertions, 78 deletions
diff --git a/include/core/SkData.h b/include/core/SkData.h index 28bf515347..60a98e00f0 100644 --- a/include/core/SkData.h +++ b/include/core/SkData.h @@ -8,9 +8,10 @@ #ifndef SkData_DEFINED #define SkData_DEFINED +#include <stdio.h> + #include "SkRefCnt.h" -struct SkFILE; class SkStream; /** @@ -119,13 +120,13 @@ public: static SkData* NewFromFileName(const char path[]); /** - * Create a new dataref from a SkFILE. - * This does not take ownership of the SkFILE, nor close it. - * The caller is free to close the SkFILE at its convenience. - * The SkFILE must be open for reading only. + * Create a new dataref from a stdio FILE. + * This does not take ownership of the FILE, nor close it. + * The caller is free to close the FILE at its convenience. + * The FILE must be open for reading only. * Returns NULL on failure. */ - static SkData* NewFromFILE(SkFILE* f); + static SkData* NewFromFILE(FILE* f); /** * Create a new dataref from a file descriptor. diff --git a/include/core/SkOSFile.h b/include/core/SkOSFile.h index 3ee3aa44a0..39a1646458 100644 --- a/include/core/SkOSFile.h +++ b/include/core/SkOSFile.h @@ -12,9 +12,9 @@ #ifndef SkOSFile_DEFINED #define SkOSFile_DEFINED -#include "SkString.h" +#include <stdio.h> -struct SkFILE; +#include "SkString.h" enum SkFILE_Flags { kRead_SkFILE_Flag = 0x01, @@ -27,30 +27,30 @@ const static char SkPATH_SEPARATOR = '\\'; const static char SkPATH_SEPARATOR = '/'; #endif -SkFILE* sk_fopen(const char path[], SkFILE_Flags); -void sk_fclose(SkFILE*); +FILE* sk_fopen(const char path[], SkFILE_Flags); +void sk_fclose(FILE*); -size_t sk_fgetsize(SkFILE*); +size_t sk_fgetsize(FILE*); /** Return true if the file could seek back to the beginning */ -bool sk_frewind(SkFILE*); +bool sk_frewind(FILE*); -size_t sk_fread(void* buffer, size_t byteCount, SkFILE*); -size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE*); +size_t sk_fread(void* buffer, size_t byteCount, FILE*); +size_t sk_fwrite(const void* buffer, size_t byteCount, FILE*); -char* sk_fgets(char* str, int size, SkFILE* f); +char* sk_fgets(char* str, int size, FILE* f); -void sk_fflush(SkFILE*); +void sk_fflush(FILE*); -bool sk_fseek(SkFILE*, size_t); -bool sk_fmove(SkFILE*, long); -size_t sk_ftell(SkFILE*); +bool sk_fseek(FILE*, size_t); +bool sk_fmove(FILE*, long); +size_t sk_ftell(FILE*); /** Maps a file into memory. Returns the address and length on success, NULL otherwise. * The mapping is read only. * When finished with the mapping, free the returned pointer with sk_fmunmap. */ -void* sk_fmmap(SkFILE* f, size_t* length); +void* sk_fmmap(FILE* f, size_t* length); /** Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise. * The mapping is read only. @@ -64,12 +64,12 @@ void* sk_fdmmap(int fd, size_t* length); void sk_fmunmap(const void* addr, size_t length); /** Returns true if the two point at the exact same filesystem object. */ -bool sk_fidentical(SkFILE* a, SkFILE* b); +bool sk_fidentical(FILE* a, FILE* b); /** Returns the underlying file descriptor for the given file. * The return value will be < 0 on failure. */ -int sk_fileno(SkFILE* f); +int sk_fileno(FILE* f); /** Returns true if something (file, directory, ???) exists at this path, * and has the specified access flags. @@ -80,7 +80,7 @@ bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0); bool sk_isdir(const char *path); // Have we reached the end of the file? -int sk_feof(SkFILE *); +int sk_feof(FILE *); // Create a new directory at this path; returns true if successful. diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 6767778343..2279f9ff10 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -224,8 +224,6 @@ public: #include "SkString.h" #include <stdio.h> -struct SkFILE; - /** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset { public: @@ -271,7 +269,7 @@ public: const void* getMemoryBase() override; private: - SkFILE* fFILE; + FILE* fFILE; SkString fName; Ownership fOwnership; // fData is lazilly initialized when needed. @@ -364,7 +362,7 @@ public: size_t bytesWritten() const override; private: - SkFILE* fFILE; + FILE* fFILE; typedef SkWStream INHERITED; }; diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp index 017c397bbf..5bf833e1f3 100644 --- a/src/core/SkData.cpp +++ b/src/core/SkData.cpp @@ -113,7 +113,7 @@ static void sk_mmap_releaseproc(const void* addr, void* ctx) { sk_fmunmap(addr, length); } -SkData* SkData::NewFromFILE(SkFILE* f) { +SkData* SkData::NewFromFILE(FILE* f) { size_t size; void* addr = sk_fmmap(f, &size); if (nullptr == addr) { @@ -124,7 +124,7 @@ SkData* SkData::NewFromFILE(SkFILE* f) { } SkData* SkData::NewFromFileName(const char path[]) { - SkFILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr; + FILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr; if (nullptr == f) { return nullptr; } diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 20e2ae9652..05867d91bf 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -185,7 +185,7 @@ SkFILEStream::SkFILEStream(const char file[]) : fName(file), fOwnership(kCallerP } SkFILEStream::SkFILEStream(FILE* file, Ownership ownership) - : fFILE((SkFILE*)file) + : fFILE(file) , fOwnership(ownership) { } @@ -850,7 +850,7 @@ bool SkDebugWStream::write(const void* buffer, size_t size) static SkData* mmap_filename(const char path[]) { - SkFILE* file = sk_fopen(path, kRead_SkFILE_Flag); + FILE* file = sk_fopen(path, kRead_SkFILE_Flag); if (nullptr == file) { return nullptr; } diff --git a/src/ports/SkOSFile_posix.cpp b/src/ports/SkOSFile_posix.cpp index 58662f382f..396de68bbe 100644 --- a/src/ports/SkOSFile_posix.cpp +++ b/src/ports/SkOSFile_posix.cpp @@ -35,8 +35,8 @@ typedef struct { ino_t ino; } SkFILEID; -static bool sk_ino(SkFILE* a, SkFILEID* id) { - int fd = fileno((FILE*)a); +static bool sk_ino(FILE* a, SkFILEID* id) { + int fd = fileno(a); if (fd < 0) { return 0; } @@ -49,7 +49,7 @@ static bool sk_ino(SkFILE* a, SkFILEID* id) { return true; } -bool sk_fidentical(SkFILE* a, SkFILE* b) { +bool sk_fidentical(FILE* a, FILE* b) { SkFILEID aID, bID; return sk_ino(a, &aID) && sk_ino(b, &bID) && aID.ino == bID.ino @@ -82,11 +82,11 @@ void* sk_fdmmap(int fd, size_t* size) { return addr; } -int sk_fileno(SkFILE* f) { - return fileno((FILE*)f); +int sk_fileno(FILE* f) { + return fileno(f); } -void* sk_fmmap(SkFILE* f, size_t* size) { +void* sk_fmmap(FILE* f, size_t* size) { int fd = sk_fileno(f); if (fd < 0) { return nullptr; diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp index 53a2bb47ec..3371bb7031 100644 --- a/src/ports/SkOSFile_stdio.cpp +++ b/src/ports/SkOSFile_stdio.cpp @@ -45,7 +45,7 @@ static FILE* ios_open_from_bundle(const char path[], const char* perm) { #endif -SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { +FILE* sk_fopen(const char path[], SkFILE_Flags flags) { char perm[4]; char* p = perm; @@ -60,16 +60,16 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { //TODO: on Windows fopen is just ASCII or the current code page, //convert to utf16 and use _wfopen - SkFILE* file = nullptr; + FILE* file = nullptr; #ifdef SK_BUILD_FOR_IOS // if read-only, try to open from bundle first if (kRead_SkFILE_Flag == flags) { - file = (SkFILE*)ios_open_from_bundle(path, perm); + file = ios_open_from_bundle(path, perm); } // otherwise just read from the Documents directory (default) if (!file) { #endif - file = (SkFILE*)::fopen(path, perm); + file = ::fopen(path, perm); #ifdef SK_BUILD_FOR_IOS } #endif @@ -80,90 +80,90 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { return file; } -char* sk_fgets(char* str, int size, SkFILE* f) { +char* sk_fgets(char* str, int size, FILE* f) { return ::fgets(str, size, (FILE *)f); } -int sk_feof(SkFILE *f) { +int sk_feof(FILE *f) { // no :: namespace qualifier because it breaks android return feof((FILE *)f); } -size_t sk_fgetsize(SkFILE* f) { +size_t sk_fgetsize(FILE* f) { SkASSERT(f); - long curr = ::ftell((FILE*)f); // remember where we are + long curr = ::ftell(f); // remember where we are if (curr < 0) { return 0; } - ::fseek((FILE*)f, 0, SEEK_END); // go to the end - long size = ::ftell((FILE*)f); // record the size + ::fseek(f, 0, SEEK_END); // go to the end + long size = ::ftell(f); // record the size if (size < 0) { size = 0; } - ::fseek((FILE*)f, curr, SEEK_SET); // go back to our prev location + ::fseek(f, curr, SEEK_SET); // go back to our prev location return size; } -bool sk_frewind(SkFILE* f) { +bool sk_frewind(FILE* f) { SkASSERT(f); - ::rewind((FILE*)f); + ::rewind(f); return true; } -size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f) { +size_t sk_fread(void* buffer, size_t byteCount, FILE* f) { SkASSERT(f); if (buffer == nullptr) { - size_t curr = ::ftell((FILE*)f); + size_t curr = ::ftell(f); if ((long)curr == -1) { - SkDEBUGF(("sk_fread: ftell(%p) returned -1 feof:%d ferror:%d\n", f, feof((FILE*)f), ferror((FILE*)f))); + SkDEBUGF(("sk_fread: ftell(%p) returned -1 feof:%d ferror:%d\n", f, feof(f), ferror(f))); return 0; } - int err = ::fseek((FILE*)f, (long)byteCount, SEEK_CUR); + int err = ::fseek(f, (long)byteCount, SEEK_CUR); if (err != 0) { SkDEBUGF(("sk_fread: fseek(%d) tell:%d failed with feof:%d ferror:%d returned:%d\n", - byteCount, curr, feof((FILE*)f), ferror((FILE*)f), err)); + byteCount, curr, feof(f), ferror(f), err)); return 0; } return byteCount; } else - return ::fread(buffer, 1, byteCount, (FILE*)f); + return ::fread(buffer, 1, byteCount, f); } -size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) { +size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* f) { SkASSERT(f); - return ::fwrite(buffer, 1, byteCount, (FILE*)f); + return ::fwrite(buffer, 1, byteCount, f); } -void sk_fflush(SkFILE* f) { +void sk_fflush(FILE* f) { SkASSERT(f); - ::fflush((FILE*)f); + ::fflush(f); } -bool sk_fseek(SkFILE* f, size_t byteCount) { - int err = ::fseek((FILE*)f, (long)byteCount, SEEK_SET); +bool sk_fseek(FILE* f, size_t byteCount) { + int err = ::fseek(f, (long)byteCount, SEEK_SET); return err == 0; } -bool sk_fmove(SkFILE* f, long byteCount) { - int err = ::fseek((FILE*)f, byteCount, SEEK_CUR); +bool sk_fmove(FILE* f, long byteCount) { + int err = ::fseek(f, byteCount, SEEK_CUR); return err == 0; } -size_t sk_ftell(SkFILE* f) { - long curr = ::ftell((FILE*)f); +size_t sk_ftell(FILE* f) { + long curr = ::ftell(f); if (curr < 0) { return 0; } return curr; } -void sk_fclose(SkFILE* f) { +void sk_fclose(FILE* f) { SkASSERT(f); - ::fclose((FILE*)f); + ::fclose(f); } bool sk_isdir(const char *path) { diff --git a/src/ports/SkOSFile_win.cpp b/src/ports/SkOSFile_win.cpp index 395a3c80a9..6bdf9ab163 100644 --- a/src/ports/SkOSFile_win.cpp +++ b/src/ports/SkOSFile_win.cpp @@ -33,7 +33,7 @@ typedef struct { ULONGLONG fMsbSize; } SkFILEID; -static bool sk_ino(SkFILE* f, SkFILEID* id) { +static bool sk_ino(FILE* f, SkFILEID* id) { int fileno = _fileno((FILE*)f); if (fileno < 0) { return false; @@ -56,7 +56,7 @@ static bool sk_ino(SkFILE* f, SkFILEID* id) { return true; } -bool sk_fidentical(SkFILE* a, SkFILE* b) { +bool sk_fidentical(FILE* a, FILE* b) { SkFILEID aID, bID; return sk_ino(a, &aID) && sk_ino(b, &bID) && aID.fLsbSize == bID.fLsbSize @@ -111,11 +111,11 @@ void* sk_fdmmap(int fileno, size_t* length) { return addr; } -int sk_fileno(SkFILE* f) { +int sk_fileno(FILE* f) { return _fileno((FILE*)f); } -void* sk_fmmap(SkFILE* f, size_t* length) { +void* sk_fmmap(FILE* f, size_t* length) { int fileno = sk_fileno(f); if (fileno < 0) { return nullptr; diff --git a/src/utils/SkRTConf.cpp b/src/utils/SkRTConf.cpp index 9c076cbb16..2dfa47efc7 100644 --- a/src/utils/SkRTConf.cpp +++ b/src/utils/SkRTConf.cpp @@ -12,7 +12,7 @@ SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) { - SkFILE *fp = sk_fopen(configFileLocation(), kRead_SkFILE_Flag); + FILE *fp = sk_fopen(configFileLocation(), kRead_SkFILE_Flag); if (!fp) { return; @@ -77,7 +77,7 @@ const char *SkRTConfRegistry::configFileLocation() const { // to trigger this, make a config file of zero size. void SkRTConfRegistry::possiblyDumpFile() const { const char *path = configFileLocation(); - SkFILE *fp = sk_fopen(path, kRead_SkFILE_Flag); + FILE *fp = sk_fopen(path, kRead_SkFILE_Flag); if (!fp) { return; } diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp index db15ee2f5a..d3ffe98d16 100644 --- a/src/utils/SkWhitelistTypefaces.cpp +++ b/src/utils/SkWhitelistTypefaces.cpp @@ -247,7 +247,7 @@ const char checksumTrailer[] = #include "SkOSFile.h" bool GenerateChecksums() { - SkFILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag); + FILE* file = sk_fopen(checksumFileName, kWrite_SkFILE_Flag); if (!file) { SkDebugf("Can't open %s for writing.\n", checksumFileName); return false; diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp index 177c9d37d5..0c7d5f4520 100644 --- a/tests/DataRefTest.cpp +++ b/tests/DataRefTest.cpp @@ -191,7 +191,7 @@ static void test_files(skiatest::Reporter* reporter) { writer.write(s, 26); } - SkFILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag); + FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag); SkAutoTUnref<SkData> r1(SkData::NewFromFILE(file)); REPORTER_ASSERT(reporter, r1.get() != nullptr); REPORTER_ASSERT(reporter, r1->size() == 26); diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp index 7b63c1cda7..f82d75d036 100644 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -683,7 +683,7 @@ static void testSkpClip(TestState* data) { return; } statusFile.appendf("%s%s", PATH_SLASH, statName.c_str()); - SkFILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag); + FILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag); if (!file) { SkDebugf("failed to create %s", statusFile.c_str()); return; diff --git a/tools/chrome_fuzz.cpp b/tools/chrome_fuzz.cpp index f05c646351..f49e12693b 100644 --- a/tools/chrome_fuzz.cpp +++ b/tools/chrome_fuzz.cpp @@ -11,7 +11,7 @@ static const int kBitmapSize = 24; static bool read_test_case(const char* filename, SkString* testdata) { - SkFILE* file = sk_fopen(filename, kRead_SkFILE_Flag); + FILE* file = sk_fopen(filename, kRead_SkFILE_Flag); if (!file) { SkDebugf("couldn't open file %s\n", filename); return false; |