2 * Copyright (C) 2007, 2008, 2011 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.
33 #include "PlatformString.h"
35 #include <wtf/Forward.h>
36 #include <wtf/MathExtras.h>
37 #include <wtf/Vector.h>
40 #include <wtf/RetainPtr.h>
46 #if defined(Q_OS_WIN32)
56 #if USE(CF) || (PLATFORM(QT) && defined(Q_WS_MAC))
57 typedef struct __CFBundle* CFBundleRef;
58 typedef const struct __CFData* CFDataRef;
62 // These are to avoid including <winbase.h> in a header for Chromium
65 typedef struct HINSTANCE__* HINSTANCE;
66 typedef HINSTANCE HMODULE;
70 typedef struct _GFileIOStream GFileIOStream;
71 typedef struct _GModule GModule;
75 typedef struct _Eina_Module Eina_Module;
82 typedef HMODULE PlatformModule;
84 typedef GModule* PlatformModule;
86 typedef Eina_Module* PlatformModule;
89 typedef CFBundleRef PlatformModule;
90 #elif !defined(QT_NO_LIBRARY)
91 typedef QLibrary* PlatformModule;
93 typedef void* PlatformModule;
96 typedef CFBundleRef PlatformModule;
98 typedef void* PlatformModule;
101 // PlatformModuleVersion
103 struct PlatformModuleVersion {
107 PlatformModuleVersion(unsigned)
113 PlatformModuleVersion(unsigned lsb, unsigned msb)
121 typedef unsigned PlatformModuleVersion;
124 // PlatformFileHandle
126 typedef QFile* PlatformFileHandle;
127 const PlatformFileHandle invalidPlatformFileHandle = 0;
129 typedef GFileIOStream* PlatformFileHandle;
130 const PlatformFileHandle invalidPlatformFileHandle = 0;
132 typedef HANDLE PlatformFileHandle;
133 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
134 // avoid using Windows headers in headers. We'd rather move this into the .cpp.
135 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
137 typedef wxFile* PlatformFileHandle;
138 const PlatformFileHandle invalidPlatformFileHandle = 0;
140 typedef int PlatformFileHandle;
141 const PlatformFileHandle invalidPlatformFileHandle = -1;
149 enum FileSeekOrigin {
150 SeekFromBeginning = 0,
156 static const char PlatformFilePathSeparator = '\\';
158 static const char PlatformFilePathSeparator = '/';
163 bool fileExists(const String&);
164 bool deleteFile(const String&);
165 bool deleteEmptyDirectory(const String&);
166 bool getFileSize(const String&, long long& result);
167 bool getFileModificationTime(const String&, time_t& result);
168 bool getFileMetadata(const String&, FileMetadata&);
169 String pathByAppendingComponent(const String& path, const String& component);
170 bool makeAllDirectories(const String& path);
171 String homeDirectoryPath();
172 String pathGetFileName(const String&);
173 String directoryName(const String&);
175 bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.
176 bool excludeFromBackup(const String&); // Returns true if successful.
178 Vector<String> listDirectory(const String& path, const String& filter = String());
180 CString fileSystemRepresentation(const String&);
182 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
184 inline double invalidFileTime() { return std::numeric_limits<double>::quiet_NaN(); }
185 inline bool isValidFileTime(double time) { return isfinite(time); }
187 // Prefix is what the filename should be prefixed with, not the full path.
188 String openTemporaryFile(const String& prefix, PlatformFileHandle&);
189 PlatformFileHandle openFile(const String& path, FileOpenMode);
190 void closeFile(PlatformFileHandle&);
191 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise.
192 long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
193 bool truncateFile(PlatformFileHandle, long long offset);
194 // Returns number of bytes actually read if successful, -1 otherwise.
195 int writeToFile(PlatformFileHandle, const char* data, int length);
196 // Returns number of bytes actually written if successful, -1 otherwise.
197 int readFromFile(PlatformFileHandle, char* data, int length);
199 // Functions for working with loadable modules.
200 bool unloadModule(PlatformModule);
202 // Encode a string for use within a file name.
203 String encodeForFileName(const String&);
206 RetainPtr<CFURLRef> pathAsURL(const String&);
210 void setMetadataURL(String& URLString, const String& referrer, const String& path);
213 #if PLATFORM(GTK) || PLATFORM(EFL)
214 String filenameToString(const char*);
215 String filenameForDisplay(const String&);
216 CString applicationDirectoryPath();
217 CString sharedResourcesPath();
218 uint64_t getVolumeFreeSizeForPath(const char*);
221 #if PLATFORM(WIN) && !OS(WINCE)
222 String localUserSpecificStorageDirectory();
223 String roamingUserSpecificStorageDirectory();
226 #if PLATFORM(WIN) && USE(CF)
227 bool safeCreateFile(const String&, CFDataRef);
230 #if ENABLE(TIZEN_FILE_SYSTEM)
231 bool copyFile(const String& sourcePath, const String& destinationPath);
232 bool getDirectorySize(const String& path, long long& size);
233 bool linkFile(const String& sourcePath, const String& destinationPath);
234 bool removeDirectory(const String& path);
235 bool renameFile(const String& sourcePath, const String& destinationPath);
238 } // namespace WebCore
240 #endif // FileSystem_h