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

Side by Side Diff: trunk/src/base/file_util_posix.cc

Issue 105823009: Revert 239280 "Move more file_util functions to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | « trunk/src/base/file_util.cc ('k') | trunk/src/base/file_util_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 results->last_accessed = Time::FromTimeT(file_info.st_atime); 682 results->last_accessed = Time::FromTimeT(file_info.st_atime);
683 results->creation_time = Time::FromTimeT(file_info.st_ctime); 683 results->creation_time = Time::FromTimeT(file_info.st_ctime);
684 #else 684 #else
685 results->last_modified = Time::FromTimeSpec(file_info.st_mtim); 685 results->last_modified = Time::FromTimeSpec(file_info.st_mtim);
686 results->last_accessed = Time::FromTimeSpec(file_info.st_atim); 686 results->last_accessed = Time::FromTimeSpec(file_info.st_atim);
687 results->creation_time = Time::FromTimeSpec(file_info.st_ctim); 687 results->creation_time = Time::FromTimeSpec(file_info.st_ctim);
688 #endif 688 #endif
689 return true; 689 return true;
690 } 690 }
691 691
692 FILE* OpenFile(const FilePath& filename, const char* mode) {
693 ThreadRestrictions::AssertIOAllowed();
694 FILE* result = NULL;
695 do {
696 result = fopen(filename.value().c_str(), mode);
697 } while (!result && errno == EINTR);
698 return result;
699 }
700
701 int ReadFile(const FilePath& filename, char* data, int size) {
702 ThreadRestrictions::AssertIOAllowed();
703 int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
704 if (fd < 0)
705 return -1;
706
707 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
708 if (int ret = IGNORE_EINTR(close(fd)) < 0)
709 return ret;
710 return bytes_read;
711 }
712
713 } // namespace base 692 } // namespace base
714 693
715 // ----------------------------------------------------------------------------- 694 // -----------------------------------------------------------------------------
716 695
717 namespace file_util { 696 namespace file_util {
718 697
719 using base::stat_wrapper_t; 698 using base::stat_wrapper_t;
720 using base::CallStat; 699 using base::CallStat;
721 using base::CallLstat; 700 using base::CallLstat;
722 using base::CreateAndOpenFdForTemporaryFile; 701 using base::CreateAndOpenFdForTemporaryFile;
(...skipping 14 matching lines...) Expand all
737 path.InsertBeforeExtensionASCII( 716 path.InsertBeforeExtensionASCII(
738 base::StringPrintf(" (%d)", uniquifier)); 717 base::StringPrintf(" (%d)", uniquifier));
739 if (mkdir(test_path.value().c_str(), 0777) == 0) 718 if (mkdir(test_path.value().c_str(), 0777) == 0)
740 return test_path; 719 return test_path;
741 else if (errno != EEXIST) 720 else if (errno != EEXIST)
742 break; 721 break;
743 } 722 }
744 return base::FilePath(); 723 return base::FilePath();
745 } 724 }
746 725
726 bool GetInode(const FilePath& path, ino_t* inode) {
727 base::ThreadRestrictions::AssertIOAllowed(); // For call to stat().
728 struct stat buffer;
729 int result = stat(path.value().c_str(), &buffer);
730 if (result < 0)
731 return false;
732
733 *inode = buffer.st_ino;
734 return true;
735 }
736
747 FILE* OpenFile(const std::string& filename, const char* mode) { 737 FILE* OpenFile(const std::string& filename, const char* mode) {
748 return OpenFile(FilePath(filename), mode); 738 return OpenFile(FilePath(filename), mode);
749 } 739 }
750 740
741 FILE* OpenFile(const FilePath& filename, const char* mode) {
742 base::ThreadRestrictions::AssertIOAllowed();
743 FILE* result = NULL;
744 do {
745 result = fopen(filename.value().c_str(), mode);
746 } while (!result && errno == EINTR);
747 return result;
748 }
749
750 int ReadFile(const FilePath& filename, char* data, int size) {
751 base::ThreadRestrictions::AssertIOAllowed();
752 int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY));
753 if (fd < 0)
754 return -1;
755
756 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size));
757 if (int ret = IGNORE_EINTR(close(fd)) < 0)
758 return ret;
759 return bytes_read;
760 }
761
751 int WriteFile(const FilePath& filename, const char* data, int size) { 762 int WriteFile(const FilePath& filename, const char* data, int size) {
752 base::ThreadRestrictions::AssertIOAllowed(); 763 base::ThreadRestrictions::AssertIOAllowed();
753 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666)); 764 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666));
754 if (fd < 0) 765 if (fd < 0)
755 return -1; 766 return -1;
756 767
757 int bytes_written = WriteFileDescriptor(fd, data, size); 768 int bytes_written = WriteFileDescriptor(fd, data, size);
758 if (int ret = IGNORE_EINTR(close(fd)) < 0) 769 if (int ret = IGNORE_EINTR(close(fd)) < 0)
759 return ret; 770 return ret;
760 return bytes_written; 771 return bytes_written;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 result = false; 969 result = false;
959 if (IGNORE_EINTR(close(outfile)) < 0) 970 if (IGNORE_EINTR(close(outfile)) < 0)
960 result = false; 971 result = false;
961 972
962 return result; 973 return result;
963 } 974 }
964 #endif // !defined(OS_MACOSX) 975 #endif // !defined(OS_MACOSX)
965 976
966 } // namespace internal 977 } // namespace internal
967 } // namespace base 978 } // namespace base
OLDNEW
« no previous file with comments | « trunk/src/base/file_util.cc ('k') | trunk/src/base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698