Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: runtime/bin/file_linux.cc

Issue 139043003: - Address warnings about 64-bit to 32-bit conversions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 71
72 72
73 int64_t File::Write(const void* buffer, int64_t num_bytes) { 73 int64_t File::Write(const void* buffer, int64_t num_bytes) {
74 ASSERT(handle_->fd() >= 0); 74 ASSERT(handle_->fd() >= 0);
75 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer, 75 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(handle_->fd(), buffer,
76 num_bytes)); 76 num_bytes));
77 } 77 }
78 78
79 79
80 off64_t File::Position() { 80 int64_t File::Position() {
81 ASSERT(handle_->fd() >= 0); 81 ASSERT(handle_->fd() >= 0);
82 return lseek64(handle_->fd(), 0, SEEK_CUR); 82 return lseek64(handle_->fd(), 0, SEEK_CUR);
83 } 83 }
84 84
85 85
86 bool File::SetPosition(off64_t position) { 86 bool File::SetPosition(int64_t position) {
87 ASSERT(handle_->fd() >= 0); 87 ASSERT(handle_->fd() >= 0);
88 return lseek64(handle_->fd(), position, SEEK_SET) >= 0; 88 return lseek64(handle_->fd(), position, SEEK_SET) >= 0;
89 } 89 }
90 90
91 91
92 bool File::Truncate(off64_t length) { 92 bool File::Truncate(int64_t length) {
93 ASSERT(handle_->fd() >= 0); 93 ASSERT(handle_->fd() >= 0);
94 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS( 94 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
95 ftruncate64(handle_->fd(), length) != -1); 95 ftruncate64(handle_->fd(), length) != -1);
96 } 96 }
97 97
98 98
99 bool File::Flush() { 99 bool File::Flush() {
100 ASSERT(handle_->fd() >= 0); 100 ASSERT(handle_->fd() >= 0);
101 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1); 101 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fsync(handle_->fd()) != -1);
102 } 102 }
103 103
104 104
105 off64_t File::Length() { 105 int64_t File::Length() {
106 ASSERT(handle_->fd() >= 0); 106 ASSERT(handle_->fd() >= 0);
107 struct stat64 st; 107 struct stat64 st;
108 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat64(handle_->fd(), &st)) == 0) { 108 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(fstat64(handle_->fd(), &st)) == 0) {
109 return st.st_size; 109 return st.st_size;
110 } 110 }
111 return -1; 111 return -1;
112 } 112 }
113 113
114 114
115 File* File::Open(const char* name, FileOpenMode mode) { 115 File* File::Open(const char* name, FileOpenMode mode) {
(...skipping 12 matching lines...) Expand all
128 } 128 }
129 if ((mode & kTruncate) != 0) { 129 if ((mode & kTruncate) != 0) {
130 flags = flags | O_TRUNC; 130 flags = flags | O_TRUNC;
131 } 131 }
132 flags |= O_CLOEXEC; 132 flags |= O_CLOEXEC;
133 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(name, flags, 0666)); 133 int fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(open64(name, flags, 0666));
134 if (fd < 0) { 134 if (fd < 0) {
135 return NULL; 135 return NULL;
136 } 136 }
137 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) { 137 if (((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) {
138 off64_t position = lseek64(fd, 0, SEEK_END); 138 int64_t position = lseek64(fd, 0, SEEK_END);
139 if (position < 0) { 139 if (position < 0) {
140 return NULL; 140 return NULL;
141 } 141 }
142 } 142 }
143 return new File(new FileHandle(fd)); 143 return new File(new FileHandle(fd));
144 } 144 }
145 145
146 146
147 File* File::OpenStdio(int fd) { 147 File* File::OpenStdio(int fd) {
148 if (fd < 0 || 2 < fd) return NULL; 148 if (fd < 0 || 2 < fd) return NULL;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 O_RDONLY | O_CLOEXEC)); 236 O_RDONLY | O_CLOEXEC));
237 if (old_fd < 0) { 237 if (old_fd < 0) {
238 return false; 238 return false;
239 } 239 }
240 int new_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( 240 int new_fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
241 open64(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode)); 241 open64(new_path, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, st.st_mode));
242 if (new_fd < 0) { 242 if (new_fd < 0) {
243 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd)); 243 VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(old_fd));
244 return false; 244 return false;
245 } 245 }
246 off64_t offset = 0; 246 int64_t offset = 0;
247 int result = 1; 247 intptr_t result = 1;
248 while (result > 0) { 248 while (result > 0) {
249 // Loop to ensure we copy everything, and not only up to 2GB. 249 // Loop to ensure we copy everything, and not only up to 2GB.
250 result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( 250 result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
251 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); 251 sendfile64(new_fd, old_fd, &offset, kMaxUint32));
252 } 252 }
253 // From sendfile man pages: 253 // From sendfile man pages:
254 // Applications may wish to fall back to read(2)/write(2) in the case 254 // Applications may wish to fall back to read(2)/write(2) in the case
255 // where sendfile() fails with EINVAL or ENOSYS. 255 // where sendfile() fails with EINVAL or ENOSYS.
256 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { 256 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) {
257 const intptr_t kBufferSize = 8 * KB; 257 const intptr_t kBufferSize = 8 * KB;
(...skipping 19 matching lines...) Expand all
277 return true; 277 return true;
278 } else if (type == kIsDirectory) { 278 } else if (type == kIsDirectory) {
279 errno = EISDIR; 279 errno = EISDIR;
280 } else { 280 } else {
281 errno = ENOENT; 281 errno = ENOENT;
282 } 282 }
283 return false; 283 return false;
284 } 284 }
285 285
286 286
287 off64_t File::LengthFromPath(const char* name) { 287 int64_t File::LengthFromPath(const char* name) {
288 struct stat64 st; 288 struct stat64 st;
289 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) { 289 if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(stat64(name, &st)) == 0) {
290 return st.st_size; 290 return st.st_size;
291 } 291 }
292 return -1; 292 return -1;
293 } 293 }
294 294
295 295
296 void File::Stat(const char* name, int64_t* data) { 296 void File::Stat(const char* name, int64_t* data) {
297 struct stat64 st; 297 struct stat64 st;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return (file_1_info.st_ino == file_2_info.st_ino && 417 return (file_1_info.st_ino == file_2_info.st_ino &&
418 file_1_info.st_dev == file_2_info.st_dev) ? 418 file_1_info.st_dev == file_2_info.st_dev) ?
419 File::kIdentical : 419 File::kIdentical :
420 File::kDifferent; 420 File::kDifferent;
421 } 421 }
422 422
423 } // namespace bin 423 } // namespace bin
424 } // namespace dart 424 } // namespace dart
425 425
426 #endif // defined(TARGET_OS_LINUX) 426 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698