| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 ASSERT(handle_->fd() >= 0); | 90 ASSERT(handle_->fd() >= 0); |
| 91 struct stat st; | 91 struct stat st; |
| 92 if (fstat(handle_->fd(), &st) == 0) { | 92 if (fstat(handle_->fd(), &st) == 0) { |
| 93 return st.st_size; | 93 return st.st_size; |
| 94 } | 94 } |
| 95 return -1; | 95 return -1; |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 File* File::Open(const char* name, FileOpenMode mode) { | 99 File* File::Open(const char* name, FileOpenMode mode) { |
| 100 int flags = O_RDONLY | O_BINARY; | 100 int flags = O_RDONLY | O_BINARY | O_NOINHERIT; |
| 101 if ((mode & kWrite) != 0) { | 101 if ((mode & kWrite) != 0) { |
| 102 flags = (O_RDWR | O_CREAT | O_BINARY); | 102 flags = (O_RDWR | O_CREAT | O_BINARY | O_NOINHERIT); |
| 103 } | 103 } |
| 104 if ((mode & kTruncate) != 0) { | 104 if ((mode & kTruncate) != 0) { |
| 105 flags = flags | O_TRUNC; | 105 flags = flags | O_TRUNC; |
| 106 } | 106 } |
| 107 int fd = open(name, flags, 0666); | 107 int fd = open(name, flags, 0666); |
| 108 if (fd < 0) { | 108 if (fd < 0) { |
| 109 return NULL; | 109 return NULL; |
| 110 } | 110 } |
| 111 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 111 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
| 112 int position = lseek(fd, 0, SEEK_END); | 112 int position = lseek(fd, 0, SEEK_END); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const char* File::StringEscapedPathSeparator() { | 225 const char* File::StringEscapedPathSeparator() { |
| 226 return "\\\\"; | 226 return "\\\\"; |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 File::StdioHandleType File::GetStdioHandleType(int fd) { | 230 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 231 // Treat all stdio handles as pipes. The Windows event handler and | 231 // Treat all stdio handles as pipes. The Windows event handler and |
| 232 // socket code will handle the different handle types. | 232 // socket code will handle the different handle types. |
| 233 return kPipe; | 233 return kPipe; |
| 234 } | 234 } |
| OLD | NEW |