Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(983)

Unified Diff: src/core/SkFDStream.cpp

Issue 15298009: Change SkStream. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Clean up, address comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkData.cpp ('k') | src/core/SkStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkFDStream.cpp
===================================================================
--- src/core/SkFDStream.cpp (revision 9222)
+++ src/core/SkFDStream.cpp (working copy)
@@ -1,104 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkStream.h"
-
-#ifdef SK_BUILD_FOR_WIN
-
-// -1 means isValid() will return false
-SkFDStream::SkFDStream(int, bool) : fFD(-1), fCloseWhenDone(false) {}
-SkFDStream::~SkFDStream() {}
-bool SkFDStream::rewind() { return false; }
-size_t SkFDStream::read(void*, size_t) { return 0; }
-
-#else
-
-#include <unistd.h>
-
-//#define TRACE_FDSTREAM
-
-SkFDStream::SkFDStream(int fileDesc, bool closeWhenDone)
- : fFD(fileDesc), fCloseWhenDone(closeWhenDone) {
-}
-
-SkFDStream::~SkFDStream() {
- if (fFD >= 0 && fCloseWhenDone) {
- ::close(fFD);
- }
-}
-
-bool SkFDStream::rewind() {
- if (fFD >= 0) {
- off_t value = ::lseek(fFD, 0, SEEK_SET);
-#ifdef TRACE_FDSTREAM
- if (value) {
- SkDebugf("xxxxxxxxxxxxxx rewind failed %d\n", value);
- }
-#endif
- return value == 0;
- }
- return false;
-}
-
-size_t SkFDStream::read(void* buffer, size_t size) {
- if (fFD >= 0) {
- if (buffer == NULL && size == 0) { // request total size
- off_t curr = ::lseek(fFD, 0, SEEK_CUR);
- if (curr < 0) {
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx lseek failed 0 CURR\n");
-#endif
- return 0; // error
- }
- off_t size = ::lseek(fFD, 0, SEEK_END);
- if (size < 0) {
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx lseek failed 0 END\n");
-#endif
- size = 0; // error
- }
- if (::lseek(fFD, curr, SEEK_SET) != curr) {
- // can't restore, error
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx lseek failed %d SET\n", curr);
-#endif
- return 0;
- }
- return (size_t) size;
- } else if (NULL == buffer) { // skip
- off_t oldCurr = ::lseek(fFD, 0, SEEK_CUR);
- if (oldCurr < 0) {
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx lseek1 failed %d CUR\n", oldCurr);
-#endif
- return 0; // error;
- }
- off_t newCurr = ::lseek(fFD, size, SEEK_CUR);
- if (newCurr < 0) {
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx lseek2 failed %d CUR\n", newCurr);
-#endif
- return 0; // error;
- }
- // return the actual amount we skipped
- return (size_t) (newCurr - oldCurr);
- } else { // read
- ssize_t actual = ::read(fFD, buffer, size);
- // our API can't return an error, so we return 0
- if (actual < 0) {
-#ifdef TRACE_FDSTREAM
- SkDebugf("xxxxxxxxxxxxx read failed %d actual %d\n", size, actual);
-#endif
- actual = 0;
- }
- return actual;
- }
- }
- return 0;
-}
-
-#endif
« no previous file with comments | « src/core/SkData.cpp ('k') | src/core/SkStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698