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 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (position < 0) { | 96 if (position < 0) { |
97 // The file is not capable of seeking. Return an error. | 97 // The file is not capable of seeking. Return an error. |
98 return -1; | 98 return -1; |
99 } | 99 } |
100 off_t result = lseek(handle_->fd(), 0, SEEK_END); | 100 off_t result = lseek(handle_->fd(), 0, SEEK_END); |
101 lseek(handle_->fd(), position, SEEK_SET); | 101 lseek(handle_->fd(), position, SEEK_SET); |
102 return result; | 102 return result; |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 File* File::Open(const char* name, bool writable) { | 106 File* File::Open(const char* name, FileOpenMode mode) { |
107 int flags = O_RDONLY; | 107 int flags = O_RDONLY; |
108 if (writable) { | 108 if ((mode & kWrite) != 0) { |
109 flags = (O_RDWR | O_CREAT | O_TRUNC); | 109 flags = (O_RDWR | O_CREAT); |
| 110 } |
| 111 if ((mode & kTruncate) != 0) { |
| 112 flags = flags | O_TRUNC; |
110 } | 113 } |
111 int fd = open(name, flags, 0666); | 114 int fd = open(name, flags, 0666); |
112 if (fd < 0) { | 115 if (fd < 0) { |
113 return NULL; | 116 return NULL; |
114 } | 117 } |
115 return new File(name, new FileHandle(fd)); | 118 return new File(name, new FileHandle(fd)); |
116 } | 119 } |
117 | 120 |
118 | 121 |
119 bool File::Exists(const char* name) { | 122 bool File::Exists(const char* name) { |
(...skipping 40 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 |