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

Side by Side Diff: net/base/file_stream_posix.cc

Issue 39301: Adds truncate to FileStream. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | « net/base/file_stream.h ('k') | net/base/file_stream_unittest.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) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 // For 64-bit file access (off_t = off64_t, lseek64, etc). 5 // For 64-bit file access (off_t = off64_t, lseek64, etc).
6 #define _FILE_OFFSET_BITS 64 6 #define _FILE_OFFSET_BITS 64
7 7
8 #include "net/base/file_stream.h" 8 #include "net/base/file_stream.h"
9 9
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 continue; 194 continue;
195 return MapErrorCode(errno); 195 return MapErrorCode(errno);
196 } 196 }
197 total_bytes_written += res; 197 total_bytes_written += res;
198 buf += res; 198 buf += res;
199 len -= res; 199 len -= res;
200 } 200 }
201 return total_bytes_written; 201 return total_bytes_written;
202 } 202 }
203 203
204 int64 FileStream::Truncate(int64 bytes) {
205 if (!IsOpen())
206 return ERR_UNEXPECTED;
207
208 // We better be open for reading.
209 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
210
211 // Seek to the position to truncate from.
212 int64 seek_position = Seek(FROM_BEGIN, bytes);
213 if (seek_position != bytes)
214 return ERR_UNEXPECTED;
215
216 // And truncate the file.
217 int result = ftruncate(file_, bytes);
218 return result == 0 ? seek_position : MapErrorCode(errno);
219 }
220
204 } // namespace net 221 } // namespace net
OLDNEW
« no previous file with comments | « net/base/file_stream.h ('k') | net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698