| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <io.h> | 6 #include <io.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (position < 0) { | 93 if (position < 0) { |
| 94 // The file is not capable of seeking. Return an error. | 94 // The file is not capable of seeking. Return an error. |
| 95 return -1; | 95 return -1; |
| 96 } | 96 } |
| 97 off_t result = lseek(handle_->fd(), 0, SEEK_END); | 97 off_t result = lseek(handle_->fd(), 0, SEEK_END); |
| 98 lseek(handle_->fd(), position, SEEK_SET); | 98 lseek(handle_->fd(), position, SEEK_SET); |
| 99 return result; | 99 return result; |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 File* File::Open(const char* name, bool writable) { | 103 File* File::Open(const char* name, FileOpenMode mode) { |
| 104 int flags = O_RDONLY | O_BINARY; | 104 int flags = O_RDONLY | O_BINARY; |
| 105 if (writable) { | 105 if ((mode & kWrite) != 0) { |
| 106 flags = (O_RDWR | O_CREAT | O_TRUNC | O_BINARY); | 106 flags = (O_RDWR | O_CREAT | O_BINARY); |
| 107 } |
| 108 if ((mode & kTruncate) != 0) { |
| 109 flags = flags | O_TRUNC; |
| 107 } | 110 } |
| 108 int fd = open(name, flags, 0666); | 111 int fd = open(name, flags, 0666); |
| 109 if (fd < 0) { | 112 if (fd < 0) { |
| 110 return NULL; | 113 return NULL; |
| 111 } | 114 } |
| 112 return new File(name, new FileHandle(fd)); | 115 return new File(name, new FileHandle(fd)); |
| 113 } | 116 } |
| 114 | 117 |
| 115 | 118 |
| 116 bool File::Exists(const char* name) { | 119 bool File::Exists(const char* name) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 163 |
| 161 | 164 |
| 162 const char* File::PathSeparator() { | 165 const char* File::PathSeparator() { |
| 163 return "\\"; | 166 return "\\"; |
| 164 } | 167 } |
| 165 | 168 |
| 166 | 169 |
| 167 const char* File::StringEscapedPathSeparator() { | 170 const char* File::StringEscapedPathSeparator() { |
| 168 return "\\\\"; | 171 return "\\\\"; |
| 169 } | 172 } |
| OLD | NEW |