1 /* libs/graphics/ports/SkOSFile_brew.cpp 2 * 3 * Copyright 2006, The Android Open Source Project 4 * Copyright 2009, Company 100, Inc. 5 * 6 * Use of this source code is governed by a BSD-style license that can be 7 * found in the LICENSE file. 8 */ 9 10 11 #include "SkOSFile.h" 12 13 #ifdef SK_BUILD_FOR_BREW 14 15 #include <AEEAppGen.h> 16 #include <AEEFile.h> 17 #include <AEEStdLib.h> 18 19 SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) 20 { 21 int err; 22 OpenFileMode mode; 23 IFileMgr* fileMgr; 24 IFile* file; 25 IShell* shell; 26 27 shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell; 28 err = ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void**)&fileMgr); 29 if (err!= SUCCESS) 30 return NULL; 31 32 if (flags & kWrite_SkFILE_Flag) 33 mode = _OFM_READWRITE; 34 else /* kRead_SkFILE_Flag */ 35 mode = _OFM_READ; 36 37 file = IFILEMGR_OpenFile(fileMgr, path, mode); 38 IFILEMGR_Release(fileMgr); 39 40 return (SkFILE*)file; 41 } 42 43 size_t sk_fgetsize(SkFILE* f) 44 { 45 FileInfo fileInfo; 46 47 IFILE_GetInfo((IFile*)f, &fileInfo); 48 return fileInfo.dwSize; 49 } 50 51 bool sk_frewind(SkFILE* f) 52 { 53 SkASSERT(f); 54 return IFILE_Seek((IFile*)f, _SEEK_START, 0) == SUCCESS; 55 } 56 57 size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f) 58 { 59 SkASSERT(f); 60 if (buffer == NULL) 61 { 62 int err = IFILE_Seek((IFile*)f, _SEEK_CURRENT, (int)byteCount); 63 if (err == EFAILED) { 64 SkDEBUGF(("sk_fread: IFILE_Seek(%d) failed returned:%d\n", byteCount, err)); 65 return 0; 66 } 67 return byteCount; 68 } 69 else 70 return IFILE_Read((IFile*)f, buffer, byteCount); 71 } 72 73 size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) 74 { 75 SkASSERT(f); 76 return IFILE_Write((IFile*)f, buffer, byteCount); 77 } 78 79 void sk_fflush(SkFILE* f) 80 { 81 SkASSERT(f); 82 } 83 84 void sk_fclose(SkFILE* f) 85 { 86 SkASSERT(f); 87 IFILE_Release((IFile*)f); 88 } 89 90 #endif 91