]> git.saurik.com Git - iphone-api.git/blob - WebCore/FileSystem.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / FileSystem.h
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(DARWIN)
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
55 typedef const struct __CFData* CFDataRef;
56
57 #if PLATFORM(WIN)
58 // These are to avoid including <winbase.h> in a header for Chromium
59 typedef void *HANDLE;
60 // Assuming STRICT
61 typedef struct HINSTANCE__* HINSTANCE;
62 typedef HINSTANCE HMODULE;
63 #endif
64
65 namespace WebCore {
66
67 class CString;
68
69 #if PLATFORM(WIN)
70 typedef HANDLE PlatformFileHandle;
71 typedef HMODULE PlatformModule;
72 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
73 // avoid using Windows headers in headers. We'd rather move this into the .cpp.
74 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
75
76 struct PlatformModuleVersion {
77 unsigned leastSig;
78 unsigned mostSig;
79
80 PlatformModuleVersion(unsigned)
81 : leastSig(0)
82 , mostSig(0)
83 {
84 }
85
86 PlatformModuleVersion(unsigned lsb, unsigned msb)
87 : leastSig(lsb)
88 , mostSig(msb)
89 {
90 }
91
92 };
93 #elif PLATFORM(QT)
94
95 typedef QFile* PlatformFileHandle;
96 const PlatformFileHandle invalidPlatformFileHandle = 0;
97 #if defined(Q_WS_MAC)
98 typedef CFBundleRef PlatformModule;
99 typedef unsigned PlatformModuleVersion;
100 #elif defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_S60)
101 typedef QLibrary* PlatformModule;
102 typedef unsigned PlatformModuleVersion;
103 #elif defined(Q_OS_WIN)
104 typedef HMODULE PlatformModule;
105 struct PlatformModuleVersion {
106 unsigned leastSig;
107 unsigned mostSig;
108
109 PlatformModuleVersion(unsigned)
110 : leastSig(0)
111 , mostSig(0)
112 {
113 }
114
115 PlatformModuleVersion(unsigned lsb, unsigned msb)
116 : leastSig(lsb)
117 , mostSig(msb)
118 {
119 }
120
121 };
122 #endif
123
124 #else
125 typedef int PlatformFileHandle;
126 #if PLATFORM(GTK)
127 typedef GModule* PlatformModule;
128 #else
129 typedef void* PlatformModule;
130 #endif
131 const PlatformFileHandle invalidPlatformFileHandle = -1;
132
133 typedef unsigned PlatformModuleVersion;
134 #endif
135
136 bool fileExists(const String&);
137 bool deleteFile(const String&);
138 bool deleteEmptyDirectory(const String&);
139 bool getFileSize(const String&, long long& result);
140 bool getFileModificationTime(const String&, time_t& result);
141 String pathByAppendingComponent(const String& path, const String& component);
142 bool makeAllDirectories(const String& path);
143 String homeDirectoryPath();
144 String pathGetFileName(const String&);
145 String directoryName(const String&);
146
147 Vector<String> listDirectory(const String& path, const String& filter = String());
148
149 CString fileSystemRepresentation(const String&);
150
151 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
152
153 // Prefix is what the filename should be prefixed with, not the full path.
154 CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
155 void closeFile(PlatformFileHandle&);
156 int writeToFile(PlatformFileHandle, const char* data, int length);
157
158 // Methods for dealing with loadable modules
159 bool unloadModule(PlatformModule);
160
161 #if PLATFORM(WIN)
162 String localUserSpecificStorageDirectory();
163 String roamingUserSpecificStorageDirectory();
164
165 bool safeCreateFile(const String&, CFDataRef);
166 #endif
167
168 #if PLATFORM(GTK)
169 String filenameToString(const char*);
170 char* filenameFromString(const String&);
171 String filenameForDisplay(const String&);
172 #endif
173
174 } // namespace WebCore
175
176 #endif // FileSystem_h