Add the FileSystem functions of iOS
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Dec 2011 05:34:02 +0000 (05:34 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Dec 2011 05:34:02 +0000 (05:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=74164

Patch by Benjamin Poulain <bpoulain@apple.com> on 2011-12-09
Reviewed by David Kilzer.

Two functions are needed on iOS for temporary files and directories.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* platform/ios/FileSystemIOS.h: Added.
* platform/ios/FileSystemIOS.mm: Added.
(WebCore::createTemporaryDirectory):
(WebCore::createTemporaryFile):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102517 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/ios/FileSystemIOS.h [new file with mode: 0644]
Source/WebCore/platform/ios/FileSystemIOS.mm [new file with mode: 0644]

index 8b96594..bede645 100644 (file)
@@ -1,3 +1,19 @@
+2011-12-09  Benjamin Poulain  <bpoulain@apple.com>
+
+        Add the FileSystem functions of iOS
+        https://bugs.webkit.org/show_bug.cgi?id=74164
+
+        Reviewed by David Kilzer.
+
+        Two functions are needed on iOS for temporary files and directories.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/ios/FileSystemIOS.h: Added.
+        * platform/ios/FileSystemIOS.mm: Added.
+        (WebCore::createTemporaryDirectory):
+        (WebCore::createTemporaryFile):
+
 2011-12-09  Jacky Jiang  <zhajiang@rim.com>
 
         Remove ResourceHandle::bufferedData() from ResourceHandleBlackBerry.cpp
index 0a7039d..2d7e02a 100644 (file)
@@ -1560,6 +1560,10 @@ _wkGetNSEventMomentumPhase
 _wkGetMacOSXVersionString
 #endif
 
+#if PLATFORM(IOS)
+__ZN7WebCore24createTemporaryDirectoryEP8NSString
+#endif
+
 _wkUnregisterUniqueIdForElement
 _wkAccessibilityHandleFocusChanged
 _wkGetAXTextMarkerTypeID
index d9356bf..a862468 100644 (file)
                265541391489811C000DFC5D /* KeyEventCodesIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 265541371489811C000DFC5D /* KeyEventCodesIOS.h */; };
                2655413A1489811C000DFC5D /* KeyEventIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 265541381489811C000DFC5D /* KeyEventIOS.mm */; };
                265541521489B233000DFC5D /* CursorIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2655414B1489AA2B000DFC5D /* CursorIOS.cpp */; };
+               26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */; };
+               26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */; };
                26E98A10130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 26E98A0F130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h */; };
                26F40D4A14904A6300CA67C4 /* EventLoopIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */; };
                2917B5611473496C0052C9D0 /* LayerFlushScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2917B55E1473496C0052C9D0 /* LayerFlushScheduler.cpp */; };
                265541371489811C000DFC5D /* KeyEventCodesIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyEventCodesIOS.h; path = ios/KeyEventCodesIOS.h; sourceTree = "<group>"; };
                265541381489811C000DFC5D /* KeyEventIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyEventIOS.mm; path = ios/KeyEventIOS.mm; sourceTree = "<group>"; };
                2655414B1489AA2B000DFC5D /* CursorIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CursorIOS.cpp; path = ios/CursorIOS.cpp; sourceTree = "<group>"; };
+               26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileSystemIOS.h; path = ios/FileSystemIOS.h; sourceTree = "<group>"; };
+               26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FileSystemIOS.mm; path = ios/FileSystemIOS.mm; sourceTree = "<group>"; };
                26E98A0F130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCodecASCIIFastPath.h; sourceTree = "<group>"; };
                26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = EventLoopIOS.mm; path = ios/EventLoopIOS.mm; sourceTree = "<group>"; };
                2917B55E1473496C0052C9D0 /* LayerFlushScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LayerFlushScheduler.cpp; path = ca/LayerFlushScheduler.cpp; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */,
+                               26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */,
+                               26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */,
                                2655414B1489AA2B000DFC5D /* CursorIOS.cpp */,
                                265541371489811C000DFC5D /* KeyEventCodesIOS.h */,
                                265541381489811C000DFC5D /* KeyEventIOS.mm */,
                                265541391489811C000DFC5D /* KeyEventCodesIOS.h in Headers */,
                                8A195932147EA16E00D1EA61 /* DOMWebKitNamedFlow.h in Headers */,
                                8A195934147EA16E00D1EA61 /* DOMWebKitNamedFlowInternal.h in Headers */,
+                               26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                D7613A501474F13F00DB8606 /* WebKitNamedFlow.cpp in Sources */,
                                D7613AC414753E5600DB8606 /* JSWebKitNamedFlow.cpp in Sources */,
                                8A195933147EA16E00D1EA61 /* DOMWebKitNamedFlow.mm in Sources */,
+                               26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebCore/platform/ios/FileSystemIOS.h b/Source/WebCore/platform/ios/FileSystemIOS.h
new file mode 100644 (file)
index 0000000..efa2f87
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileSystemIOS_h
+#define FileSystemIOS_h
+
+@class NSString;
+
+namespace WebCore {
+
+NSString *createTemporaryDirectory(NSString *directoryPrefix);
+NSString *createTemporaryFile(NSString *directoryPath, NSString *filePrefix);
+
+} // namespace WebCore
+
+#endif // FileSystemIOS_h
diff --git a/Source/WebCore/platform/ios/FileSystemIOS.mm b/Source/WebCore/platform/ios/FileSystemIOS.mm
new file mode 100644 (file)
index 0000000..36aba9a
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "FileSystemIOS.h"
+
+#import "FileSystem.h"
+
+namespace WebCore {
+
+NSString *createTemporaryDirectory(NSString *directoryPrefix)
+{
+    NSString *tempDirectory = NSTemporaryDirectory();
+    if (!tempDirectory || ![tempDirectory length])
+        return nil;
+
+    if (!directoryPrefix || ![directoryPrefix length])
+        return nil;
+
+    NSString *tempDirectoryComponent = [directoryPrefix stringByAppendingString:@"-XXXXXXXX"];
+    const char* tempDirectoryCString = [[tempDirectory stringByAppendingPathComponent:tempDirectoryComponent] fileSystemRepresentation];
+    if (!tempDirectoryCString)
+        return nil;
+
+    const size_t length = strlen(tempDirectoryCString);
+    ASSERT(length <= MAXPATHLEN);
+    if (length > MAXPATHLEN)
+        return nil;
+
+    const size_t lengthPlusNullTerminator = length + 1;
+    Vector<char, MAXPATHLEN + 1> path(lengthPlusNullTerminator);
+    memcpy(path.data(), tempDirectoryCString, lengthPlusNullTerminator);
+
+    if (!mkdtemp(path.data()))
+        return nil;
+
+    return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path.data() length:length];
+}
+
+NSString *createTemporaryFile(NSString *directoryPath, NSString *filePrefix)
+{
+    if (!directoryPath || ![directoryPath length] || !filePrefix || ![filePrefix length])
+        return nil;
+
+    NSString *tempFileComponent = [filePrefix stringByAppendingString:@"-XXXXXXXX"];
+    const char* templatePathCString = [[directoryPath stringByAppendingPathComponent:tempFileComponent] fileSystemRepresentation];
+    if (!templatePathCString)
+        return nil;
+
+    const size_t length = strlen(templatePathCString);
+    ASSERT(length <= MAXPATHLEN);
+    if (length > MAXPATHLEN)
+        return nil;
+
+    const size_t lengthPlusNullTerminator = length + 1;
+    Vector<char, MAXPATHLEN + 1> path(lengthPlusNullTerminator);
+    memcpy(path.data(), templatePathCString, lengthPlusNullTerminator);
+
+    int fd = mkstemp(path.data());
+    if (fd < 0)
+        return nil;
+
+    int err = fchmod(fd, S_IRUSR | S_IWUSR);
+    if (err < 0) {
+        close(fd);
+        unlink(path.data());
+        return nil;
+    }
+
+    close(fd);
+    return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path.data() length:length];
+}
+
+} // namespace WebCore
+