| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #include <libgen.h> | 9 #include <libgen.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 if (position < 0) { | 97 if (position < 0) { |
| 98 // The file is not capable of seeking. Return an error. | 98 // The file is not capable of seeking. Return an error. |
| 99 return -1; | 99 return -1; |
| 100 } | 100 } |
| 101 off_t result = lseek(handle_->fd(), 0, SEEK_END); | 101 off_t result = lseek(handle_->fd(), 0, SEEK_END); |
| 102 lseek(handle_->fd(), position, SEEK_SET); | 102 lseek(handle_->fd(), position, SEEK_SET); |
| 103 return result; | 103 return result; |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 File* File::Open(const char* name, bool writable) { | 107 File* File::Open(const char* name, FileOpenMode mode) { |
| 108 int flags = O_RDONLY; | 108 int flags = O_RDONLY; |
| 109 if (writable) { | 109 if ((mode & kWrite) != 0) { |
| 110 flags = (O_RDWR | O_CREAT | O_TRUNC); | 110 flags = (O_RDWR | O_CREAT); |
| 111 } |
| 112 if ((mode & kTruncate) != 0) { |
| 113 flags = flags | O_TRUNC; |
| 111 } | 114 } |
| 112 int fd = open(name, flags, 0666); | 115 int fd = open(name, flags, 0666); |
| 113 if (fd < 0) { | 116 if (fd < 0) { |
| 114 return NULL; | 117 return NULL; |
| 115 } | 118 } |
| 116 return new File(name, new FileHandle(fd)); | 119 return new File(name, new FileHandle(fd)); |
| 117 } | 120 } |
| 118 | 121 |
| 119 | 122 |
| 120 bool File::Exists(const char* name) { | 123 bool File::Exists(const char* name) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 170 |
| 168 | 171 |
| 169 const char* File::PathSeparator() { | 172 const char* File::PathSeparator() { |
| 170 return "/"; | 173 return "/"; |
| 171 } | 174 } |
| 172 | 175 |
| 173 | 176 |
| 174 const char* File::StringEscapedPathSeparator() { | 177 const char* File::StringEscapedPathSeparator() { |
| 175 return "/"; | 178 return "/"; |
| 176 } | 179 } |
| OLD | NEW |