blob: 50e133ff2f9e99cd47dec124d9d3bac62ee788a7 [file] [log] [blame]
reed@google.com0e14e0b2011-01-11 15:53:52 +00001/* libs/graphics/ports/SkOSFile_brew.cpp
epoger@google.comfd03db02011-07-28 14:24:55 +00002 *
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
reed@google.com0e14e0b2011-01-11 15:53:52 +000010
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
19SkFILE* 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
43size_t sk_fgetsize(SkFILE* f)
44{
45 FileInfo fileInfo;
46
47 IFILE_GetInfo((IFile*)f, &fileInfo);
48 return fileInfo.dwSize;
49}
50
51bool sk_frewind(SkFILE* f)
52{
53 SkASSERT(f);
54 return IFILE_Seek((IFile*)f, _SEEK_START, 0) == SUCCESS;
55}
56
57size_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
73size_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
79void sk_fflush(SkFILE* f)
80{
81 SkASSERT(f);
82}
83
84void sk_fclose(SkFILE* f)
85{
86 SkASSERT(f);
87 IFILE_Release((IFile*)f);
88}
89
90#endif