OLD | NEW |
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 Loading... |
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 |
OLD | NEW |