SkOSFile.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2006 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License");
58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *      http://www.apache.org/licenses/LICENSE-2.0
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS,
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License.
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkOSFile_DEFINED
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkOSFile_DEFINED
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkString.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    #include <dirent.h>
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkFILE;
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comenum SkFILE_Flags {
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    kRead_SkFILE_Flag   = 0x01,
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    kWrite_SkFILE_Flag  = 0x02
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkFILE* sk_fopen(const char path[], SkFILE_Flags);
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid    sk_fclose(SkFILE*);
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comsize_t  sk_fgetsize(SkFILE*);
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Return true if the file could seek back to the beginning
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool    sk_frewind(SkFILE*);
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comsize_t  sk_fread(void* buffer, size_t byteCount, SkFILE*);
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comsize_t  sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid    sk_fflush(SkFILE*);
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint     sk_fseek( SkFILE*, size_t, int );
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comsize_t  sk_ftell( SkFILE* );
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkOSFile {
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class Iter {
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Iter();
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Iter(const char path[], const char suffix[] = NULL);
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~Iter();
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void reset(const char path[], const char suffix[] = NULL);
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool next(SkString* name, bool getDir = false);
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_WIN
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        HANDLE      fHandle;
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        uint16_t*   fPath16;
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        DIR*        fDIR;
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkString    fPath, fSuffix;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkUTF16_Str {
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkUTF16_Str(const char src[]);
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkUTF16_Str()
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    {
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        sk_free(fStr);
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const uint16_t* get() const { return fStr; }
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint16_t*   fStr;
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
86