Home | History | Annotate | Download | only in core
      1 /*
      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 
     27 struct SkFILE;
     28 
     29 enum SkFILE_Flags {
     30     kRead_SkFILE_Flag   = 0x01,
     31     kWrite_SkFILE_Flag  = 0x02
     32 };
     33 
     34 SkFILE* sk_fopen(const char path[], SkFILE_Flags);
     35 void    sk_fclose(SkFILE*);
     36 
     37 size_t  sk_fgetsize(SkFILE*);
     38 /** Return true if the file could seek back to the beginning
     39 */
     40 bool    sk_frewind(SkFILE*);
     41 
     42 size_t  sk_fread(void* buffer, size_t byteCount, SkFILE*);
     43 size_t  sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
     44 void    sk_fflush(SkFILE*);
     45 
     46 int     sk_fseek( SkFILE*, size_t, int );
     47 size_t  sk_ftell( SkFILE* );
     48 
     49 class SkOSFile {
     50 public:
     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 
     71 class SkUTF16_Str {
     72 public:
     73     SkUTF16_Str(const char src[]);
     74     ~SkUTF16_Str()
     75     {
     76         sk_free(fStr);
     77     }
     78     const uint16_t* get() const { return fStr; }
     79 
     80 private:
     81     uint16_t*   fStr;
     82 };
     83 
     84 #endif
     85 
     86