| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "bin/file.h" | 5 #include "bin/file.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if ((mode & kWrite) != 0) { | 109 if ((mode & kWrite) != 0) { |
| 110 flags = (O_RDWR | O_CREAT); | 110 flags = (O_RDWR | O_CREAT); |
| 111 } | 111 } |
| 112 if ((mode & kTruncate) != 0) { | 112 if ((mode & kTruncate) != 0) { |
| 113 flags = flags | O_TRUNC; | 113 flags = flags | O_TRUNC; |
| 114 } | 114 } |
| 115 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); | 115 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); |
| 116 if (fd < 0) { | 116 if (fd < 0) { |
| 117 return NULL; | 117 return NULL; |
| 118 } | 118 } |
| 119 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 120 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); |
| 121 if (position < 0) { |
| 122 return NULL; |
| 123 } |
| 124 } |
| 119 return new File(name, new FileHandle(fd)); | 125 return new File(name, new FileHandle(fd)); |
| 120 } | 126 } |
| 121 | 127 |
| 122 | 128 |
| 123 bool File::Exists(const char* name) { | 129 bool File::Exists(const char* name) { |
| 124 struct stat st; | 130 struct stat st; |
| 125 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 131 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 126 return S_ISREG(st.st_mode); // Deal with symlinks? | 132 return S_ISREG(st.st_mode); // Deal with symlinks? |
| 127 } else { | 133 } else { |
| 128 return false; | 134 return false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 172 |
| 167 | 173 |
| 168 const char* File::PathSeparator() { | 174 const char* File::PathSeparator() { |
| 169 return "/"; | 175 return "/"; |
| 170 } | 176 } |
| 171 | 177 |
| 172 | 178 |
| 173 const char* File::StringEscapedPathSeparator() { | 179 const char* File::StringEscapedPathSeparator() { |
| 174 return "/"; | 180 return "/"; |
| 175 } | 181 } |
| OLD | NEW |