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

Side by Side Diff: base/file_util_win.cc

Issue 11208: Implement some missing file util functions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month 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 | « base/file_util_posix.cc ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <time.h> 10 #include <time.h>
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 488 }
489 489
490 FILE* OpenFile(const std::string& filename, const char* mode) { 490 FILE* OpenFile(const std::string& filename, const char* mode) {
491 FILE* file; 491 FILE* file;
492 if (fopen_s(&file, filename.c_str(), mode) != 0) { 492 if (fopen_s(&file, filename.c_str(), mode) != 0) {
493 return NULL; 493 return NULL;
494 } 494 }
495 return file; 495 return file;
496 } 496 }
497 497
498 FILE* OpenFile(const std::wstring& filename, const char* mode) {
499 return OpenFile(FilePath(filename), mode);
500 }
501
502 int ReadFile(const std::wstring& filename, char* data, int size) { 498 int ReadFile(const std::wstring& filename, char* data, int size) {
503 ScopedHandle file(CreateFile(filename.c_str(), 499 ScopedHandle file(CreateFile(filename.c_str(),
504 GENERIC_READ, 500 GENERIC_READ,
505 FILE_SHARE_READ | FILE_SHARE_WRITE, 501 FILE_SHARE_READ | FILE_SHARE_WRITE,
506 NULL, 502 NULL,
507 OPEN_EXISTING, 503 OPEN_EXISTING,
508 FILE_FLAG_SEQUENTIAL_SCAN, 504 FILE_FLAG_SEQUENTIAL_SCAN,
509 NULL)); 505 NULL));
510 if (file == INVALID_HANDLE_VALUE) 506 if (file == INVALID_HANDLE_VALUE)
511 return -1; 507 return -1;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 // TODO(evanm): the old behavior of this function was to always strip the 583 // TODO(evanm): the old behavior of this function was to always strip the
588 // trailing slash. We duplicate this here, but it shouldn't be necessary 584 // trailing slash. We duplicate this here, but it shouldn't be necessary
589 // when everyone is using the appropriate FilePath APIs. 585 // when everyone is using the appropriate FilePath APIs.
590 std::wstring dir_str(system_buffer); 586 std::wstring dir_str(system_buffer);
591 file_util::TrimTrailingSeparator(&dir_str); 587 file_util::TrimTrailingSeparator(&dir_str);
592 *dir = FilePath(dir_str); 588 *dir = FilePath(dir_str);
593 return true; 589 return true;
594 } 590 }
595 591
596 // Sets the current working directory for the process. 592 // Sets the current working directory for the process.
597 bool SetCurrentDirectory(const std::wstring& current_directory) { 593 bool SetCurrentDirectory(const FilePath& directory) {
598 BOOL ret = ::SetCurrentDirectory(current_directory.c_str()); 594 BOOL ret = ::SetCurrentDirectory(directory.value().c_str());
599 return (ret ? true : false); 595 return ret != 0;
600 } 596 }
601 597
602 /////////////////////////////////////////////// 598 ///////////////////////////////////////////////
603 599
604 600
605 FileEnumerator::FileEnumerator(const std::wstring& root_path, 601 FileEnumerator::FileEnumerator(const std::wstring& root_path,
606 bool recursive, 602 bool recursive,
607 FileEnumerator::FILE_TYPE file_type) 603 FileEnumerator::FILE_TYPE file_type)
608 : recursive_(recursive), 604 : recursive_(recursive),
609 file_type_(file_type), 605 file_type_(file_type),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // it to pending_paths_ so we scan it after we finish scanning this 682 // it to pending_paths_ so we scan it after we finish scanning this
687 // directory. 683 // directory.
688 pending_paths_.push(cur_file); 684 pending_paths_.push(cur_file);
689 } 685 }
690 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); 686 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
691 } 687 }
692 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); 688 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
693 } 689 }
694 690
695 } // namespace file_util 691 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698