aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-03-10 13:08:15 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-10 19:58:46 +0000
commit4d1955c43aaab045511b74a495dfbea4ef0057c5 (patch)
tree23d0f457f69b98bde35dc9a3afa32451ee5f6694 /include
parentdc9f0dbe4cdcdf6fead5fc28532d58f7d998a447 (diff)
Fix SkFILEStream.
Change-Id: I8c66e4e3e857227aed3d0bc497982f4c0d96d917 Reviewed-on: https://skia-review.googlesource.com/9498 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkOSFile.h13
-rw-r--r--include/core/SkStream.h36
2 files changed, 19 insertions, 30 deletions
diff --git a/include/core/SkOSFile.h b/include/core/SkOSFile.h
index 876135596b..88ad958b1c 100644
--- a/include/core/SkOSFile.h
+++ b/include/core/SkOSFile.h
@@ -24,20 +24,12 @@ FILE* sk_fopen(const char path[], SkFILE_Flags);
void sk_fclose(FILE*);
size_t sk_fgetsize(FILE*);
-/** Return true if the file could seek back to the beginning
-*/
-bool sk_frewind(FILE*);
-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, FILE* f);
-
void sk_fflush(FILE*);
void sk_fsync(FILE*);
-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.
@@ -73,8 +65,9 @@ bool sk_exists(const char *path, SkFILE_Flags = (SkFILE_Flags)0);
// Returns true if a directory exists at this path.
bool sk_isdir(const char *path);
-// Have we reached the end of the file?
-int sk_feof(FILE *);
+// Like pread, but may affect the file position marker.
+// Returns the number of bytes read or SIZE_MAX if failed.
+size_t sk_qread(FILE*, void* buffer, size_t count, size_t offset);
// Create a new directory at this path; returns true if successful.
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 419ef7b723..10929a8343 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -12,6 +12,8 @@
#include "SkRefCnt.h"
#include "SkScalar.h"
+#include <memory.h>
+
class SkStream;
class SkStreamRewindable;
class SkStreamSeekable;
@@ -232,7 +234,6 @@ public:
////////////////////////////////////////////////////////////////////////////////////////
-#include "SkString.h"
#include <stdio.h>
/** A stream that wraps a C FILE* file stream. */
@@ -241,28 +242,20 @@ public:
/** Initialize the stream by calling sk_fopen on the specified path.
* This internal stream will be closed in the destructor.
*/
- explicit SkFILEStream(const char path[] = NULL);
+ explicit SkFILEStream(const char path[] = nullptr);
- enum Ownership {
- kCallerPasses_Ownership,
- kCallerRetains_Ownership
- };
/** Initialize the stream with an existing C file stream.
- * While this stream exists, it assumes exclusive access to the C file stream.
- * The C file stream will be closed in the destructor unless the caller specifies
- * kCallerRetains_Ownership.
+ * The C file stream will be closed in the destructor.
*/
- explicit SkFILEStream(FILE* file, Ownership ownership = kCallerPasses_Ownership);
+ explicit SkFILEStream(FILE* file);
virtual ~SkFILEStream();
/** Returns true if the current path could be opened. */
- bool isValid() const { return fFILE != NULL; }
+ bool isValid() const { return fFILE != nullptr; }
- /** Close the current file, and open a new file with the specified path.
- * If path is NULL, just close the current file.
- */
- void setPath(const char path[]);
+ /** Close this SkFILEStream. */
+ void close();
size_t read(void* buffer, size_t size) override;
bool isAtEnd() const override;
@@ -280,11 +273,14 @@ public:
const void* getMemoryBase() override;
private:
- FILE* fFILE;
- SkString fName;
- Ownership fOwnership;
- // fData is lazilly initialized when needed.
- mutable sk_sp<SkData> fData;
+ explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset);
+ explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset, size_t originalOffset);
+
+ std::shared_ptr<FILE> fFILE;
+ // My own council will I keep on sizes and offsets.
+ size_t fSize;
+ size_t fOffset;
+ size_t fOriginalOffset;
typedef SkStreamAsset INHERITED;
};