• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 //
11 #ifndef SkOSFile_DEFINED
12 #define SkOSFile_DEFINED
13 
14 #include "SkString.h"
15 
16 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
17     #include <dirent.h>
18 #endif
19 
20 struct SkFILE;
21 
22 enum SkFILE_Flags {
23     kRead_SkFILE_Flag   = 0x01,
24     kWrite_SkFILE_Flag  = 0x02
25 };
26 
27 SkFILE* sk_fopen(const char path[], SkFILE_Flags);
28 void    sk_fclose(SkFILE*);
29 
30 size_t  sk_fgetsize(SkFILE*);
31 /** Return true if the file could seek back to the beginning
32 */
33 bool    sk_frewind(SkFILE*);
34 
35 size_t  sk_fread(void* buffer, size_t byteCount, SkFILE*);
36 size_t  sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
37 void    sk_fflush(SkFILE*);
38 
39 int     sk_fseek( SkFILE*, size_t, int );
40 size_t  sk_ftell( SkFILE* );
41 
42 class SkOSFile {
43 public:
44     class Iter {
45     public:
46         Iter();
47         Iter(const char path[], const char suffix[] = NULL);
48         ~Iter();
49 
50         void reset(const char path[], const char suffix[] = NULL);
51         /** If getDir is true, only returns directories.
52             Results are undefined if true and false calls are
53             interleaved on a single iterator.
54         */
55         bool next(SkString* name, bool getDir = false);
56 
57     private:
58 #ifdef SK_BUILD_FOR_WIN
59         HANDLE      fHandle;
60         uint16_t*   fPath16;
61 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
62         DIR*        fDIR;
63         SkString    fPath, fSuffix;
64 #endif
65     };
66 };
67 
68 class SkUTF16_Str {
69 public:
70     SkUTF16_Str(const char src[]);
~SkUTF16_Str()71     ~SkUTF16_Str()
72     {
73         sk_free(fStr);
74     }
get()75     const uint16_t* get() const { return fStr; }
76 
77 private:
78     uint16_t*   fStr;
79 };
80 
81 #endif
82 
83