Eliminate SkFILE: it always is the same as FILE.

Review URL: https://codereview.chromium.org/1467533003
This commit is contained in:
halcanary 2015-11-20 13:47:49 -08:00 committed by Commit bot
parent 90ba095c45
commit d76be9c79b
13 changed files with 77 additions and 78 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;