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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 int FileStream::Open(const FilePath& path, int open_flags) { | 325 int FileStream::Open(const FilePath& path, int open_flags) { |
326 if (IsOpen()) { | 326 if (IsOpen()) { |
327 DLOG(FATAL) << "File is already open!"; | 327 DLOG(FATAL) << "File is already open!"; |
328 return ERR_UNEXPECTED; | 328 return ERR_UNEXPECTED; |
329 } | 329 } |
330 | 330 |
331 open_flags_ = open_flags; | 331 open_flags_ = open_flags; |
332 file_ = base::CreatePlatformFile(path.ToWStringHack(), open_flags_, NULL); | 332 file_ = base::CreatePlatformFile(path, open_flags_, NULL); |
333 if (file_ == base::kInvalidPlatformFileValue) { | 333 if (file_ == base::kInvalidPlatformFileValue) { |
334 LOG(WARNING) << "Failed to open file: " << errno | 334 LOG(WARNING) << "Failed to open file: " << errno |
335 << " (" << path.ToWStringHack() << ")"; | 335 << " (" << path.ToWStringHack() << ")"; |
336 return MapErrorCode(errno); | 336 return MapErrorCode(errno); |
337 } | 337 } |
338 | 338 |
339 if (open_flags_ & base::PLATFORM_FILE_ASYNC) { | 339 if (open_flags_ & base::PLATFORM_FILE_ASYNC) { |
340 async_context_.reset(new AsyncContext()); | 340 async_context_.reset(new AsyncContext()); |
341 } | 341 } |
342 | 342 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 int64 seek_position = Seek(FROM_BEGIN, bytes); | 451 int64 seek_position = Seek(FROM_BEGIN, bytes); |
452 if (seek_position != bytes) | 452 if (seek_position != bytes) |
453 return ERR_UNEXPECTED; | 453 return ERR_UNEXPECTED; |
454 | 454 |
455 // And truncate the file. | 455 // And truncate the file. |
456 int result = ftruncate(file_, bytes); | 456 int result = ftruncate(file_, bytes); |
457 return result == 0 ? seek_position : MapErrorCode(errno); | 457 return result == 0 ? seek_position : MapErrorCode(errno); |
458 } | 458 } |
459 | 459 |
460 } // namespace net | 460 } // namespace net |
OLD | NEW |