1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1.  Redistributions of source code must retain the above copyright
10 *     notice, this list of conditions and the following disclaimer.
11 * 2.  Redistributions in binary form must reproduce the above copyright
12 *     notice, this list of conditions and the following disclaimer in the
13 *     documentation and/or other materials provided with the distribution.
14 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 *     its contributors may be used to endorse or promote products derived
16 *     from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef FileSystem_h
31#define FileSystem_h
32
33#if PLATFORM(GTK)
34#include <gmodule.h>
35#endif
36#if PLATFORM(QT)
37#include <QFile>
38#include <QLibrary>
39#if defined(Q_OS_WIN32)
40#include <windows.h>
41#endif
42#endif
43
44#if PLATFORM(CF) || (PLATFORM(QT) && defined(Q_WS_MAC))
45#include <CoreFoundation/CFBundle.h>
46#endif
47
48#include <time.h>
49
50#include <wtf/Platform.h>
51#include <wtf/Vector.h>
52
53#include "PlatformString.h"
54
55typedef const struct __CFData* CFDataRef;
56
57#if OS(WINDOWS)
58// These are to avoid including <winbase.h> in a header for Chromium
59typedef void *HANDLE;
60// Assuming STRICT
61typedef struct HINSTANCE__* HINSTANCE;
62typedef HINSTANCE HMODULE;
63#endif
64
65namespace WebCore {
66
67class CString;
68
69// PlatformModule
70#if OS(WINDOWS)
71typedef HMODULE PlatformModule;
72#elif PLATFORM(QT)
73#if defined(Q_WS_MAC)
74typedef CFBundleRef PlatformModule;
75#else
76typedef QLibrary* PlatformModule;
77#endif // defined(Q_WS_MAC)
78#elif PLATFORM(GTK)
79typedef GModule* PlatformModule;
80#elif PLATFORM(CF)
81typedef CFBundleRef PlatformModule;
82#else
83typedef void* PlatformModule;
84#endif
85
86// PlatformModuleVersion
87#if OS(WINDOWS)
88struct PlatformModuleVersion {
89    unsigned leastSig;
90    unsigned mostSig;
91
92    PlatformModuleVersion(unsigned)
93        : leastSig(0)
94        , mostSig(0)
95    {
96    }
97
98    PlatformModuleVersion(unsigned lsb, unsigned msb)
99        : leastSig(lsb)
100        , mostSig(msb)
101    {
102    }
103
104};
105#else
106typedef unsigned PlatformModuleVersion;
107#endif
108
109// PlatformFileHandle
110#if PLATFORM(QT)
111typedef QFile* PlatformFileHandle;
112const PlatformFileHandle invalidPlatformFileHandle = 0;
113#elif OS(WINDOWS)
114typedef HANDLE PlatformFileHandle;
115// FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
116// avoid using Windows headers in headers.  We'd rather move this into the .cpp.
117const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
118#else
119typedef int PlatformFileHandle;
120const PlatformFileHandle invalidPlatformFileHandle = -1;
121#endif
122
123bool fileExists(const String&);
124bool deleteFile(const String&);
125bool deleteEmptyDirectory(const String&);
126bool getFileSize(const String&, long long& result);
127bool getFileModificationTime(const String&, time_t& result);
128String pathByAppendingComponent(const String& path, const String& component);
129bool makeAllDirectories(const String& path);
130String homeDirectoryPath();
131String pathGetFileName(const String&);
132String directoryName(const String&);
133
134Vector<String> listDirectory(const String& path, const String& filter = String());
135
136CString fileSystemRepresentation(const String&);
137
138inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
139
140// Prefix is what the filename should be prefixed with, not the full path.
141CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
142void closeFile(PlatformFileHandle&);
143int writeToFile(PlatformFileHandle, const char* data, int length);
144
145// Methods for dealing with loadable modules
146bool unloadModule(PlatformModule);
147
148#if PLATFORM(WIN)
149String localUserSpecificStorageDirectory();
150String roamingUserSpecificStorageDirectory();
151
152bool safeCreateFile(const String&, CFDataRef);
153#endif
154
155#if PLATFORM(GTK)
156String filenameToString(const char*);
157char* filenameFromString(const String&);
158String filenameForDisplay(const String&);
159#endif
160
161#if PLATFORM(CHROMIUM)
162String pathGetDisplayFileName(const String&);
163#endif
164
165} // namespace WebCore
166
167#endif // FileSystem_h
168