blob: de8090c5ecb4a00c3b32336f525c23a879980499 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//
18#ifndef SkOSFile_DEFINED
19#define SkOSFile_DEFINED
20
21#include "SkString.h"
22
23#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
24 #include <dirent.h>
25#endif
26
27struct SkFILE;
28
29enum SkFILE_Flags {
30 kRead_SkFILE_Flag = 0x01,
31 kWrite_SkFILE_Flag = 0x02
32};
33
34SkFILE* sk_fopen(const char path[], SkFILE_Flags);
35void sk_fclose(SkFILE*);
36
37size_t sk_fgetsize(SkFILE*);
38/** Return true if the file could seek back to the beginning
39*/
40bool sk_frewind(SkFILE*);
41
42size_t sk_fread(void* buffer, size_t byteCount, SkFILE*);
43size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
44void sk_fflush(SkFILE*);
45
46int sk_fseek( SkFILE*, size_t, int );
47size_t sk_ftell( SkFILE* );
48
49class SkOSFile {
50public:
51 class Iter {
52 public:
53 Iter();
54 Iter(const char path[], const char suffix[] = NULL);
55 ~Iter();
56
57 void reset(const char path[], const char suffix[] = NULL);
58 bool next(SkString* name, bool getDir = false);
59
60 private:
61#ifdef SK_BUILD_FOR_WIN
62 HANDLE fHandle;
63 uint16_t* fPath16;
64#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
65 DIR* fDIR;
66 SkString fPath, fSuffix;
67#endif
68 };
69};
70
71class SkUTF16_Str {
72public:
73 SkUTF16_Str(const char src[]);
74 ~SkUTF16_Str()
75 {
76 sk_free(fStr);
77 }
78 const uint16_t* get() const { return fStr; }
79
80private:
81 uint16_t* fStr;
82};
83
84#endif
85