SkOSFile_brew.cpp revision 40528743dbb9ce7f39f093e0cdc47849ac8887cf
1/* libs/graphics/ports/SkOSFile_brew.cpp 2** 3** Copyright 2006, The Android Open Source Project 4** Copyright 2009, Company 100, Inc. 5** 6** Licensed under the Apache License, Version 2.0 (the "License"); 7** you may not use this file except in compliance with the License. 8** You may obtain a copy of the License at 9** 10** http://www.apache.org/licenses/LICENSE-2.0 11** 12** Unless required by applicable law or agreed to in writing, software 13** distributed under the License is distributed on an "AS IS" BASIS, 14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15** See the License for the specific language governing permissions and 16** limitations under the License. 17*/ 18 19#include "SkOSFile.h" 20 21#ifdef SK_BUILD_FOR_BREW 22 23#include <AEEAppGen.h> 24#include <AEEFile.h> 25#include <AEEStdLib.h> 26 27SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) 28{ 29 int err; 30 OpenFileMode mode; 31 IFileMgr* fileMgr; 32 IFile* file; 33 IShell* shell; 34 35 shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell; 36 err = ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void**)&fileMgr); 37 if (err!= SUCCESS) 38 return NULL; 39 40 if (flags & kWrite_SkFILE_Flag) 41 mode = _OFM_READWRITE; 42 else /* kRead_SkFILE_Flag */ 43 mode = _OFM_READ; 44 45 file = IFILEMGR_OpenFile(fileMgr, path, mode); 46 IFILEMGR_Release(fileMgr); 47 48 return (SkFILE*)file; 49} 50 51size_t sk_fgetsize(SkFILE* f) 52{ 53 FileInfo fileInfo; 54 55 IFILE_GetInfo((IFile*)f, &fileInfo); 56 return fileInfo.dwSize; 57} 58 59bool sk_frewind(SkFILE* f) 60{ 61 SkASSERT(f); 62 return IFILE_Seek((IFile*)f, _SEEK_START, 0) == SUCCESS; 63} 64 65size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f) 66{ 67 SkASSERT(f); 68 if (buffer == NULL) 69 { 70 int err = IFILE_Seek((IFile*)f, _SEEK_CURRENT, (int)byteCount); 71 if (err == EFAILED) { 72 SkDEBUGF(("sk_fread: IFILE_Seek(%d) failed returned:%d\n", byteCount, err)); 73 return 0; 74 } 75 return byteCount; 76 } 77 else 78 return IFILE_Read((IFile*)f, buffer, byteCount); 79} 80 81size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) 82{ 83 SkASSERT(f); 84 return IFILE_Write((IFile*)f, buffer, byteCount); 85} 86 87void sk_fflush(SkFILE* f) 88{ 89 SkASSERT(f); 90} 91 92void sk_fclose(SkFILE* f) 93{ 94 SkASSERT(f); 95 IFILE_Release((IFile*)f); 96} 97 98#endif 99 100