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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 | 73 |
74 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 74 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
75 ASSERT(handle_->fd() >= 0); | 75 ASSERT(handle_->fd() >= 0); |
76 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer, | 76 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer, |
77 num_bytes)); | 77 num_bytes)); |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 off64_t File::Position() { | 81 int64_t File::Position() { |
82 ASSERT(handle_->fd() >= 0); | 82 ASSERT(handle_->fd() >= 0); |
83 return lseek(handle_->fd(), 0, SEEK_CUR); | 83 return lseek(handle_->fd(), 0, SEEK_CUR); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 bool File::SetPosition(off64_t position) { | 87 bool File::SetPosition(int64_t position) { |
88 ASSERT(handle_->fd() >= 0); | 88 ASSERT(handle_->fd() >= 0); |
89 return lseek(handle_->fd(), position, SEEK_SET) >= 0; | 89 return lseek(handle_->fd(), position, SEEK_SET) >= 0; |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 bool File::Truncate(off64_t length) { | 93 bool File::Truncate(int64_t length) { |
94 ASSERT(handle_->fd() >= 0); | 94 ASSERT(handle_->fd() >= 0); |
95 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS( | 95 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
96 ftruncate(handle_->fd(), length) != -1); | 96 ftruncate(handle_->fd(), length) != -1); |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 bool File::Flush() { | 100 bool File::Flush() { |
101 ASSERT(handle_->fd() >= 0); | 101 ASSERT(handle_->fd() >= 0); |
102 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1); | 102 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 off64_t File::Length() { | 106 int64_t File::Length() { |
107 ASSERT(handle_->fd() >= 0); | 107 ASSERT(handle_->fd() >= 0); |
108 struct stat st; | 108 struct stat st; |
109 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat(handle_->fd(), &st)) == 0) { | 109 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat(handle_->fd(), &st)) == 0) { |
110 return st.st_size; | 110 return st.st_size; |
111 } | 111 } |
112 return -1; | 112 return -1; |
113 } | 113 } |
114 | 114 |
115 | 115 |
116 File* File::Open(const char* name, FileOpenMode mode) { | 116 File* File::Open(const char* name, FileOpenMode mode) { |
(...skipping 12 matching lines...) Expand all Loading... |
129 } | 129 } |
130 if ((mode & kTruncate) != 0) { | 130 if ((mode & kTruncate) != 0) { |
131 flags = flags | O_TRUNC; | 131 flags = flags | O_TRUNC; |
132 } | 132 } |
133 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open(name, flags, 0666)); | 133 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open(name, flags, 0666)); |
134 if (fd < 0) { | 134 if (fd < 0) { |
135 return NULL; | 135 return NULL; |
136 } | 136 } |
137 FDUtils::SetCloseOnExec(fd); | 137 FDUtils::SetCloseOnExec(fd); |
138 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { | 138 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { |
139 off64_t position = lseek(fd, 0, SEEK_END); | 139 int64_t position = lseek(fd, 0, SEEK_END); |
140 if (position < 0) { | 140 if (position < 0) { |
141 return NULL; | 141 return NULL; |
142 } | 142 } |
143 } | 143 } |
144 return new File(new FileHandle(fd)); | 144 return new File(new FileHandle(fd)); |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 File* File::OpenStdio(int fd) { | 148 File* File::OpenStdio(int fd) { |
149 if (fd < 0 || 2 < fd) return NULL; | 149 if (fd < 0 || 2 < fd) return NULL; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return copyfile(old_path, new_path, NULL, COPYFILE_ALL) == 0; | 232 return copyfile(old_path, new_path, NULL, COPYFILE_ALL) == 0; |
233 } else if (type == kIsDirectory) { | 233 } else if (type == kIsDirectory) { |
234 errno = EISDIR; | 234 errno = EISDIR; |
235 } else { | 235 } else { |
236 errno = ENOENT; | 236 errno = ENOENT; |
237 } | 237 } |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 off64_t File::LengthFromPath(const char* name) { | 242 int64_t File::LengthFromPath(const char* name) { |
243 struct stat st; | 243 struct stat st; |
244 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat(name, &st)) == 0) { | 244 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat(name, &st)) == 0) { |
245 return st.st_size; | 245 return st.st_size; |
246 } | 246 } |
247 return -1; | 247 return -1; |
248 } | 248 } |
249 | 249 |
250 | 250 |
251 void File::Stat(const char* name, int64_t* data) { | 251 void File::Stat(const char* name, int64_t* data) { |
252 struct stat st; | 252 struct stat st; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 return (file_1_info.st_ino == file_2_info.st_ino && | 378 return (file_1_info.st_ino == file_2_info.st_ino && |
379 file_1_info.st_dev == file_2_info.st_dev) ? | 379 file_1_info.st_dev == file_2_info.st_dev) ? |
380 File::kIdentical : | 380 File::kIdentical : |
381 File::kDifferent; | 381 File::kDifferent; |
382 } | 382 } |
383 | 383 |
384 } // namespace bin | 384 } // namespace bin |
385 } // namespace dart | 385 } // namespace dart |
386 | 386 |
387 #endif // defined(TARGET_OS_MACOS) | 387 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |