Changeset 57182 in webkit
- Timestamp:
- Apr 6, 2010 6:29:04 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r57180 r57182 1 2010-04-06 Kinuko Yasuda <kinuko@chromium.org> 2 3 Reviewed by Jian Li. 4 5 Add basic FileSystem operations for FileReader/FileWriter support for POSIX (incl. Mac) 6 https://bugs.webkit.org/show_bug.cgi?id=36938 7 8 No new tests; will be added when we implement upper layers. 9 10 * platform/FileSystem.h: 11 (WebCore::): 12 * platform/posix/FileSystemPOSIX.cpp: 13 (WebCore::openFile): 14 (WebCore::closeFile): 15 (WebCore::seekFile): 16 (WebCore::truncateFile): 17 (WebCore::writeToFile): 18 (WebCore::readFromFile): 19 1 20 2010-04-06 Nicolas Weber <thakis@chromium.org> 2 21 -
trunk/WebCore/platform/FileSystem.h
r56825 r57182 27 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 28 */ 29 29 30 30 #ifndef FileSystem_h 31 31 #define FileSystem_h … … 123 123 #endif 124 124 125 enum FileOpenMode { 126 OpenForRead = 0, 127 OpenForWrite 128 }; 129 130 enum FileSeekOrigin { 131 SeekFromBeginning = 0, 132 SeekFromCurrent, 133 SeekFromEnd 134 }; 135 125 136 bool fileExists(const String&); 126 137 bool deleteFile(const String&); … … 142 153 // Prefix is what the filename should be prefixed with, not the full path. 143 154 WTF::CString openTemporaryFile(const char* prefix, PlatformFileHandle&); 155 PlatformFileHandle openFile(const String& path, FileOpenMode); 144 156 void closeFile(PlatformFileHandle&); 157 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise. 158 long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin); 159 bool truncateFile(PlatformFileHandle, long long offset); 160 // Returns number of bytes actually read if successful, -1 otherwise. 145 161 int writeToFile(PlatformFileHandle, const char* data, int length); 162 // Returns number of bytes actually written if successful, -1 otherwise. 163 int readFromFile(PlatformFileHandle, char* data, int length); 146 164 147 165 // Methods for dealing with loadable modules -
trunk/WebCore/platform/posix/FileSystemPOSIX.cpp
r56825 r57182 31 31 32 32 #include "PlatformString.h" 33 #include <errno.h> 34 #include <libgen.h> 35 #include <sys/stat.h> 36 #include <unistd.h> 33 37 #include <wtf/text/CString.h> 34 35 #include <sys/stat.h>36 #include <libgen.h>37 #include <unistd.h>38 38 39 39 namespace WebCore { … … 64 64 // unlink(...) returns 0 on successful deletion of the path and non-zero in any other case (including invalid permissions or non-existent file) 65 65 return !unlink(fsRep.data()); 66 } 67 68 PlatformFileHandle openFile(const String& path, FileOpenMode mode) 69 { 70 int platformFlag = 0; 71 if (mode == OpenForRead) 72 platformFlag |= O_RDONLY; 73 else if (mode == OpenForWrite) 74 platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); 75 return open(path.utf8().data(), platformFlag, 0666); 76 } 77 78 void closeFile(PlatformFileHandle& handle) 79 { 80 if (isHandleValid(handle)) { 81 close(handle); 82 handle = invalidPlatformFileHandle; 83 } 84 } 85 86 long long seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin origin) 87 { 88 int whence = SEEK_SET; 89 switch (origin) { 90 case SeekFromBeginning: 91 whence = SEEK_SET; 92 break; 93 case SeekFromCurrent: 94 whence = SEEK_CUR; 95 break; 96 case SeekFromEnd: 97 whence = SEEK_END; 98 break; 99 default: 100 ASSERT_NOT_REACHED(); 101 } 102 return static_cast<long long>(lseek(handle, offset, whence)); 103 } 104 105 bool truncateFile(PlatformFileHandle handle, long long offset) 106 { 107 // ftruncate returns 0 to indicate the success. 108 return !ftruncate(handle, offset); 109 } 110 111 int writeToFile(PlatformFileHandle handle, const char* data, int length) 112 { 113 do { 114 int bytesWritten = write(handle, data, static_cast<size_t>(length)); 115 if (bytesWritten >= 0) 116 return bytesWritten; 117 } while (errno == EINTR); 118 return -1; 119 } 120 121 int readFromFile(PlatformFileHandle handle, char* data, int length) 122 { 123 do { 124 int bytesRead = read(handle, data, static_cast<size_t>(length)); 125 if (bytesRead >= 0) 126 return bytesRead; 127 } while (errno == EINTR); 128 return -1; 66 129 } 67 130
Note: See TracChangeset
for help on using the changeset viewer.