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

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

Issue 160288: Assorted fixes for 64-bit. (Closed)
Patch Set: Created 11 years, 4 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
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 return size - cur_pos; 376 return size - cur_pos;
377 } 377 }
378 378
379 int FileStream::Read( 379 int FileStream::Read(
380 char* buf, int buf_len, CompletionCallback* callback) { 380 char* buf, int buf_len, CompletionCallback* callback) {
381 if (!IsOpen()) 381 if (!IsOpen())
382 return ERR_UNEXPECTED; 382 return ERR_UNEXPECTED;
383 383
384 // read(..., 0) will return 0, which indicates end-of-file. 384 // read(..., 0) will return 0, which indicates end-of-file.
385 DCHECK(buf_len > 0 && buf_len <= SSIZE_MAX); 385 DCHECK(buf_len > 0);
386 DCHECK(open_flags_ & base::PLATFORM_FILE_READ); 386 DCHECK(open_flags_ & base::PLATFORM_FILE_READ);
387 387
388 if (async_context_.get()) { 388 if (async_context_.get()) {
389 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); 389 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC);
390 // If we're in async, make sure we don't have a request in flight. 390 // If we're in async, make sure we don't have a request in flight.
391 DCHECK(!async_context_->callback()); 391 DCHECK(!async_context_->callback());
392 async_context_->InitiateAsyncRead(file_, buf, buf_len, callback); 392 async_context_->InitiateAsyncRead(file_, buf, buf_len, callback);
393 return ERR_IO_PENDING; 393 return ERR_IO_PENDING;
394 } else { 394 } else {
395 return ReadFile(file_, buf, buf_len); 395 return ReadFile(file_, buf, buf_len);
(...skipping 17 matching lines...) Expand all
413 buf += bytes_read; 413 buf += bytes_read;
414 to_read -= bytes_read; 414 to_read -= bytes_read;
415 } while (bytes_total < buf_len); 415 } while (bytes_total < buf_len);
416 416
417 return bytes_total; 417 return bytes_total;
418 } 418 }
419 419
420 int FileStream::Write( 420 int FileStream::Write(
421 const char* buf, int buf_len, CompletionCallback* callback) { 421 const char* buf, int buf_len, CompletionCallback* callback) {
422 // write(..., 0) will return 0, which indicates end-of-file. 422 // write(..., 0) will return 0, which indicates end-of-file.
423 DCHECK(buf_len > 0 && buf_len <= SSIZE_MAX); 423 DCHECK(buf_len > 0);
424 424
425 if (!IsOpen()) 425 if (!IsOpen())
426 return ERR_UNEXPECTED; 426 return ERR_UNEXPECTED;
427 427
428 if (async_context_.get()) { 428 if (async_context_.get()) {
429 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC); 429 DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC);
430 // If we're in async, make sure we don't have a request in flight. 430 // If we're in async, make sure we don't have a request in flight.
431 DCHECK(!async_context_->callback()); 431 DCHECK(!async_context_->callback());
432 async_context_->InitiateAsyncWrite(file_, buf, buf_len, callback); 432 async_context_->InitiateAsyncWrite(file_, buf, buf_len, callback);
433 return ERR_IO_PENDING; 433 return ERR_IO_PENDING;
(...skipping 13 matching lines...) Expand all
447 int64 seek_position = Seek(FROM_BEGIN, bytes); 447 int64 seek_position = Seek(FROM_BEGIN, bytes);
448 if (seek_position != bytes) 448 if (seek_position != bytes)
449 return ERR_UNEXPECTED; 449 return ERR_UNEXPECTED;
450 450
451 // And truncate the file. 451 // And truncate the file.
452 int result = ftruncate(file_, bytes); 452 int result = ftruncate(file_, bytes);
453 return result == 0 ? seek_position : MapErrorCode(errno); 453 return result == 0 ? seek_position : MapErrorCode(errno);
454 } 454 }
455 455
456 } // namespace net 456 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698