2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
36 #if defined(Q_OS_WIN32)
41 #if PLATFORM(CF) || (PLATFORM(QT) && defined(Q_WS_MAC))
42 #include <CoreFoundation/CFBundle.h>
45 #include "PlatformString.h"
47 #include <wtf/Forward.h>
48 #include <wtf/Vector.h>
50 typedef const struct __CFData* CFDataRef;
53 // These are to avoid including <winbase.h> in a header for Chromium
56 typedef struct HINSTANCE__* HINSTANCE;
57 typedef HINSTANCE HMODULE;
61 typedef struct _IFile IFile;
65 typedef struct _GFileIOStream GFileIOStream;
66 typedef struct _GModule GModule;
73 typedef HMODULE PlatformModule;
76 typedef CFBundleRef PlatformModule;
77 #elif !defined(QT_NO_LIBRARY)
78 typedef QLibrary* PlatformModule;
80 typedef void* PlatformModule;
83 typedef GModule* PlatformModule;
85 typedef CFBundleRef PlatformModule;
87 typedef void* PlatformModule;
90 // PlatformModuleVersion
92 struct PlatformModuleVersion {
96 PlatformModuleVersion(unsigned)
102 PlatformModuleVersion(unsigned lsb, unsigned msb)
110 typedef unsigned PlatformModuleVersion;
113 // PlatformFileHandle
115 typedef QFile* PlatformFileHandle;
116 const PlatformFileHandle invalidPlatformFileHandle = 0;
118 typedef HANDLE PlatformFileHandle;
119 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
120 // avoid using Windows headers in headers. We'd rather move this into the .cpp.
121 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
122 #elif PLATFORM(BREWMP)
123 typedef IFile* PlatformFileHandle;
124 const PlatformFileHandle invalidPlatformFileHandle = 0;
125 typedef void* PlatformModule;
126 typedef unsigned PlatformModuleVersion;
128 typedef GFileIOStream* PlatformFileHandle;
129 const PlatformFileHandle invalidPlatformFileHandle = 0;
131 typedef int PlatformFileHandle;
132 const PlatformFileHandle invalidPlatformFileHandle = -1;
140 enum FileSeekOrigin {
141 SeekFromBeginning = 0,
147 static const char PlatformFilePathSeparator = '\\';
149 static const char PlatformFilePathSeparator = '/';
152 void revealFolderInOS(const String&);
153 bool fileExists(const String&);
154 bool deleteFile(const String&);
155 bool deleteEmptyDirectory(const String&);
156 bool getFileSize(const String&, long long& result);
157 bool getFileModificationTime(const String&, time_t& result);
158 String pathByAppendingComponent(const String& path, const String& component);
159 bool makeAllDirectories(const String& path);
160 String homeDirectoryPath();
161 String pathGetFileName(const String&);
162 String directoryName(const String&);
164 Vector<String> listDirectory(const String& path, const String& filter = String());
166 CString fileSystemRepresentation(const String&);
168 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
170 // Prefix is what the filename should be prefixed with, not the full path.
171 CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
172 PlatformFileHandle openFile(const String& path, FileOpenMode);
173 void closeFile(PlatformFileHandle&);
174 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise.
175 long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
176 bool truncateFile(PlatformFileHandle, long long offset);
177 // Returns number of bytes actually read if successful, -1 otherwise.
178 int writeToFile(PlatformFileHandle, const char* data, int length);
179 // Returns number of bytes actually written if successful, -1 otherwise.
180 int readFromFile(PlatformFileHandle, char* data, int length);
182 // Methods for dealing with loadable modules
183 bool unloadModule(PlatformModule);
185 // Encode a string for use within a file name.
186 String encodeForFileName(const String&);
189 String localUserSpecificStorageDirectory();
190 String roamingUserSpecificStorageDirectory();
192 bool safeCreateFile(const String&, CFDataRef);
196 String filenameToString(const char*);
197 String filenameForDisplay(const String&);
198 CString applicationDirectoryPath();
201 #if PLATFORM(CHROMIUM)
202 String pathGetDisplayFileName(const String&);
205 } // namespace WebCore
207 #endif // FileSystem_h