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/Vector.h>
39 #include <wtf/RetainPtr.h>
45 #if defined(Q_OS_WIN32)
50 #if USE(CF) || (PLATFORM(QT) && defined(Q_WS_MAC))
51 typedef struct __CFBundle* CFBundleRef;
52 typedef const struct __CFData* CFDataRef;
56 // These are to avoid including <winbase.h> in a header for Chromium
59 typedef struct HINSTANCE__* HINSTANCE;
60 typedef HINSTANCE HMODULE;
64 typedef struct _IFile IFile;
68 typedef struct _GFileIOStream GFileIOStream;
69 typedef struct _GModule GModule;
76 typedef HMODULE PlatformModule;
79 typedef CFBundleRef PlatformModule;
80 #elif !defined(QT_NO_LIBRARY)
81 typedef QLibrary* PlatformModule;
83 typedef void* PlatformModule;
86 typedef GModule* PlatformModule;
88 typedef CFBundleRef PlatformModule;
90 typedef void* PlatformModule;
93 // PlatformModuleVersion
95 struct PlatformModuleVersion {
99 PlatformModuleVersion(unsigned)
105 PlatformModuleVersion(unsigned lsb, unsigned msb)
113 typedef unsigned PlatformModuleVersion;
116 // PlatformFileHandle
118 typedef QFile* PlatformFileHandle;
119 const PlatformFileHandle invalidPlatformFileHandle = 0;
121 typedef HANDLE PlatformFileHandle;
122 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
123 // avoid using Windows headers in headers. We'd rather move this into the .cpp.
124 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
125 #elif PLATFORM(BREWMP)
126 typedef IFile* PlatformFileHandle;
127 const PlatformFileHandle invalidPlatformFileHandle = 0;
129 typedef GFileIOStream* PlatformFileHandle;
130 const PlatformFileHandle invalidPlatformFileHandle = 0;
132 typedef int PlatformFileHandle;
133 const PlatformFileHandle invalidPlatformFileHandle = -1;
141 enum FileSeekOrigin {
142 SeekFromBeginning = 0,
148 static const char PlatformFilePathSeparator = '\\';
150 static const char PlatformFilePathSeparator = '/';
153 void revealFolderInOS(const String&);
154 bool fileExists(const String&);
155 bool deleteFile(const String&);
156 bool deleteEmptyDirectory(const String&);
157 bool getFileSize(const String&, long long& result);
158 bool getFileModificationTime(const String&, time_t& result);
159 String pathByAppendingComponent(const String& path, const String& component);
160 bool makeAllDirectories(const String& path);
161 String homeDirectoryPath();
162 String pathGetFileName(const String&);
163 String directoryName(const String&);
165 bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.
166 bool excludeFromBackup(const String&); // Returns true if successful.
168 Vector<String> listDirectory(const String& path, const String& filter = String());
170 CString fileSystemRepresentation(const String&);
172 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
174 // Prefix is what the filename should be prefixed with, not the full path.
175 CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
176 PlatformFileHandle openFile(const String& path, FileOpenMode);
177 void closeFile(PlatformFileHandle&);
178 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise.
179 long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
180 bool truncateFile(PlatformFileHandle, long long offset);
181 // Returns number of bytes actually read if successful, -1 otherwise.
182 int writeToFile(PlatformFileHandle, const char* data, int length);
183 // Returns number of bytes actually written if successful, -1 otherwise.
184 int readFromFile(PlatformFileHandle, char* data, int length);
186 // Functions for working with loadable modules.
187 bool unloadModule(PlatformModule);
189 // Encode a string for use within a file name.
190 String encodeForFileName(const String&);
193 RetainPtr<CFURLRef> pathAsURL(const String&);
196 #if PLATFORM(CHROMIUM)
197 String pathGetDisplayFileName(const String&);
201 String filenameToString(const char*);
202 String filenameForDisplay(const String&);
203 CString applicationDirectoryPath();
206 #if PLATFORM(WIN) && !OS(WINCE)
207 String localUserSpecificStorageDirectory();
208 String roamingUserSpecificStorageDirectory();
209 bool safeCreateFile(const String&, CFDataRef);
212 } // namespace WebCore
214 #endif // FileSystem_h