| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if ((mode & kWrite) != 0) { | 110 if ((mode & kWrite) != 0) { |
| 111 flags = (O_RDWR | O_CREAT); | 111 flags = (O_RDWR | O_CREAT); |
| 112 } | 112 } |
| 113 if ((mode & kTruncate) != 0) { | 113 if ((mode & kTruncate) != 0) { |
| 114 flags = flags | O_TRUNC; | 114 flags = flags | O_TRUNC; |
| 115 } | 115 } |
| 116 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); | 116 int fd = TEMP_FAILURE_RETRY(open(name, flags, 0666)); |
| 117 if (fd < 0) { | 117 if (fd < 0) { |
| 118 return NULL; | 118 return NULL; |
| 119 } | 119 } |
| 120 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 121 int position = TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_END)); |
| 122 if (position < 0) { |
| 123 return NULL; |
| 124 } |
| 125 } |
| 120 return new File(name, new FileHandle(fd)); | 126 return new File(name, new FileHandle(fd)); |
| 121 } | 127 } |
| 122 | 128 |
| 123 | 129 |
| 124 bool File::Exists(const char* name) { | 130 bool File::Exists(const char* name) { |
| 125 struct stat st; | 131 struct stat st; |
| 126 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 132 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 127 return S_ISREG(st.st_mode); // Deal with symlinks? | 133 return S_ISREG(st.st_mode); // Deal with symlinks? |
| 128 } else { | 134 } else { |
| 129 return false; | 135 return false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 179 |
| 174 | 180 |
| 175 const char* File::PathSeparator() { | 181 const char* File::PathSeparator() { |
| 176 return "/"; | 182 return "/"; |
| 177 } | 183 } |
| 178 | 184 |
| 179 | 185 |
| 180 const char* File::StringEscapedPathSeparator() { | 186 const char* File::StringEscapedPathSeparator() { |
| 181 return "/"; | 187 return "/"; |
| 182 } | 188 } |
| OLD | NEW |