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

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

Issue 9034005: Change the behavior of open on files to not truncate by default (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comment.s Created 8 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_impl.dart ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <libgen.h> 9 #include <libgen.h>
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (position < 0) { 96 if (position < 0) {
97 // The file is not capable of seeking. Return an error. 97 // The file is not capable of seeking. Return an error.
98 return -1; 98 return -1;
99 } 99 }
100 off_t result = lseek(handle_->fd(), 0, SEEK_END); 100 off_t result = lseek(handle_->fd(), 0, SEEK_END);
101 lseek(handle_->fd(), position, SEEK_SET); 101 lseek(handle_->fd(), position, SEEK_SET);
102 return result; 102 return result;
103 } 103 }
104 104
105 105
106 File* File::Open(const char* name, bool writable) { 106 File* File::Open(const char* name, FileOpenMode mode) {
107 int flags = O_RDONLY; 107 int flags = O_RDONLY;
108 if (writable) { 108 if ((mode & kWrite) != 0) {
109 flags = (O_RDWR | O_CREAT | O_TRUNC); 109 flags = (O_RDWR | O_CREAT);
110 }
111 if ((mode & kTruncate) != 0) {
112 flags = flags | O_TRUNC;
110 } 113 }
111 int fd = open(name, flags, 0666); 114 int fd = open(name, flags, 0666);
112 if (fd < 0) { 115 if (fd < 0) {
113 return NULL; 116 return NULL;
114 } 117 }
115 return new File(name, new FileHandle(fd)); 118 return new File(name, new FileHandle(fd));
116 } 119 }
117 120
118 121
119 bool File::Exists(const char* name) { 122 bool File::Exists(const char* name) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 163
161 164
162 const char* File::PathSeparator() { 165 const char* File::PathSeparator() {
163 return "/"; 166 return "/";
164 } 167 }
165 168
166 169
167 const char* File::StringEscapedPathSeparator() { 170 const char* File::StringEscapedPathSeparator() {
168 return "/"; 171 return "/";
169 } 172 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698