summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-08 20:16:08 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-08 20:16:08 +0000
commit5af2edb98c8ebde32dcc51dcde9b02bea82468a3 (patch)
tree8e575497f7343fd6eca212253c4fad33bc5cfb68 /base
parent764be58b4a7cc20271571be59118d260aad13966 (diff)
downloadchromium_src-5af2edb98c8ebde32dcc51dcde9b02bea82468a3.zip
chromium_src-5af2edb98c8ebde32dcc51dcde9b02bea82468a3.tar.gz
chromium_src-5af2edb98c8ebde32dcc51dcde9b02bea82468a3.tar.bz2
* add base_paths_mac.mm to mac port
* add file_util_posix.cc to mac port (NOTE: untested on linux) * a bit of cleanup in path_service.cc related to this * a few more cleanups to file_util.cc to make it build for mac git-svn-id: svn://svn.chromium.org/chrome/trunk/src@589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.xcodeproj/project.pbxproj40
-rw-r--r--base/base_paths.h10
-rw-r--r--base/base_paths_mac.h54
-rw-r--r--base/base_paths_mac.mm73
-rw-r--r--base/file_util.cc77
-rw-r--r--base/file_util_linux.cc55
-rw-r--r--base/file_util_mac.mm55
-rw-r--r--base/file_util_posix.cc299
-rw-r--r--base/file_util_win.cc15
-rw-r--r--base/path_service.cc37
10 files changed, 644 insertions, 71 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index 71c9806..05caab8 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -95,10 +95,15 @@
829E365F0DC0FB1C00819EBF /* stats_table.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403790D92D2CF0006B936 /* stats_table.cc */; };
829E36730DC0FBAD00819EBF /* thread_local_storage_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 829E36720DC0FBAD00819EBF /* thread_local_storage_posix.cc */; };
829E36740DC0FBB100819EBF /* thread_local_storage.h in Headers */ = {isa = PBXBuildFile; fileRef = 825403820D92D2CF0006B936 /* thread_local_storage.h */; };
+ A5A026190E48FE1500498DA9 /* base_paths_mac.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A026180E48FE1500498DA9 /* base_paths_mac.h */; };
+ A5A0261F0E48FF2200498DA9 /* path_service.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0261E0E48FF2200498DA9 /* path_service.cc */; };
+ A5A026550E4A214600498DA9 /* file_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A026540E4A214600498DA9 /* file_util.cc */; };
+ A5A0268E0E4A2BDC00498DA9 /* file_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */; };
+ A5A0270B0E4A630D00498DA9 /* file_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */; };
+ A5A0276C0E4BA33700498DA9 /* build_config.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A0276B0E4BA33700498DA9 /* build_config.h */; };
ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */; };
ABF4B99E0DC2BB6000A6E319 /* clipboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */; };
ABF4B9A70DC2BBAE00A6E319 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 829E31330DBFDB6F00819EBF /* CoreGraphics.framework */; };
- ABF4B9AA0DC2BC2A00A6E319 /* file_util_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B9A90DC2BC2A00A6E319 /* file_util_mac.cc */; };
ABF4B9AD0DC2BC4800A6E319 /* file_version_info.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */; };
ABF4B9AF0DC2BC6200A6E319 /* json_reader.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254031B0D92D1F40006B936 /* json_reader.cc */; };
ABF4B9B00DC2BC6500A6E319 /* json_writer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254031D0D92D1F40006B936 /* json_writer.cc */; };
@@ -254,42 +259,42 @@
isa = PBXContainerItemProxy;
containerPortal = E45A2C680E47AEFF00DB1196 /* gtest.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = D2AAC045055464E500DB518D /* gtest */;
+ remoteGlobalIDString = D2AAC045055464E500DB518D;
remoteInfo = gtest;
};
E49F18C60E4CBAED00386AEC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD5408A0D6F743F003CD41E /* icudata_stub */;
+ remoteGlobalIDString = 7BD5408A0D6F743F003CD41E;
remoteInfo = icudata_stub;
};
E49F18C80E4CBAED00386AEC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD53AAA0D6F6671003CD41E /* icuuc */;
+ remoteGlobalIDString = 7BD53AAA0D6F6671003CD41E;
remoteInfo = icuuc;
};
E49F18CA0E4CBAED00386AEC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD53EA50D6F6FC7003CD41E /* icui18n */;
+ remoteGlobalIDString = 7BD53EA50D6F6FC7003CD41E;
remoteInfo = icui18n;
};
E49F18CC0E4CBAED00386AEC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD540250D6F727B003CD41E /* icutu */;
+ remoteGlobalIDString = 7BD540250D6F727B003CD41E;
remoteInfo = icutu;
};
E49F18CE0E4CBAED00386AEC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 82C262C30DCF9411005CFE91 /* icudatastatic */;
+ remoteGlobalIDString = 82C262C30DCF9411005CFE91;
remoteInfo = icudatastatic;
};
/* End PBXContainerItemProxy section */
@@ -452,9 +457,14 @@
829E36720DC0FBAD00819EBF /* thread_local_storage_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_storage_posix.cc; sourceTree = "<group>"; };
82E23FCB0D9C219600F8B40A /* platform_thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform_thread.h; sourceTree = "<group>"; };
82E23FCC0D9C219600F8B40A /* platform_thread.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = platform_thread.cc; sourceTree = "<group>"; };
+ A5A026180E48FE1500498DA9 /* base_paths_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = base_paths_mac.h; sourceTree = "<group>"; };
+ A5A0261E0E48FF2200498DA9 /* path_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service.cc; sourceTree = "<group>"; };
+ A5A026540E4A214600498DA9 /* file_util.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util.cc; sourceTree = "<group>"; };
+ A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_posix.cc; sourceTree = "<group>"; };
+ A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_util_mac.mm; sourceTree = "<group>"; };
+ A5A0276B0E4BA33700498DA9 /* build_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = build_config.h; path = ../build/build_config.h; sourceTree = SOURCE_ROOT; };
ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = base_paths_mac.mm; sourceTree = "<group>"; };
ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; sourceTree = "<group>"; };
- ABF4B9A90DC2BC2A00A6E319 /* file_util_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_mac.cc; sourceTree = "<group>"; };
ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_version_info.mm; sourceTree = "<group>"; };
ABF4B9B40DC2BC9F00A6E319 /* path_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service.cc; sourceTree = "<group>"; };
E45629E40E27C058005E4685 /* rect_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rect_unittest.cc; sourceTree = "<group>"; };
@@ -536,6 +546,11 @@
825402B60D92D0E20006B936 /* base */ = {
isa = PBXGroup;
children = (
+ A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */,
+ A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */,
+ A5A026540E4A214600498DA9 /* file_util.cc */,
+ A5A0261E0E48FF2200498DA9 /* path_service.cc */,
+ A5A026180E48FE1500498DA9 /* base_paths_mac.h */,
E49115EB0E47B461001EE8C3 /* at_exit.h */,
E49115EC0E47B461001EE8C3 /* at_exit.cc */,
E49115F30E47B496001EE8C3 /* at_exit_unittest.cc */,
@@ -550,6 +565,7 @@
825402CD0D92D1390006B936 /* basictypes.h */,
825402D70D92D15E0006B936 /* blapi.h */,
825402D80D92D15E0006B936 /* blapit.h */,
+ A5A0276B0E4BA33700498DA9 /* build_config.h */,
825402DB0D92D1730006B936 /* clipboard.h */,
ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */,
825402DD0D92D1730006B936 /* clipboard_util.h */,
@@ -566,7 +582,6 @@
825402FF0D92D1BC0006B936 /* event_recorder.cc */,
825403000D92D1BC0006B936 /* event_recorder.h */,
825403030D92D1C50006B936 /* file_util.h */,
- ABF4B9A90DC2BC2A00A6E319 /* file_util_mac.cc */,
E4562AB10E27D8D7005E4685 /* file_version_info_unittest.cc */,
825403070D92D1CD0006B936 /* file_version_info.h */,
ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */,
@@ -844,8 +859,10 @@
E48A066B0E3F70B500172919 /* convolver.h in Headers */,
E49357230E422A38008F8B09 /* timer.h in Headers */,
E49115EE0E47B461001EE8C3 /* at_exit.h in Headers */,
+ A5A026190E48FE1500498DA9 /* base_paths_mac.h in Headers */,
7B4C5D890E4915D800679E8F /* float_util.h in Headers */,
7B4C5F490E4B6BF900679E8F /* sys_string_conversions.h in Headers */,
+ A5A0276C0E4BA33700498DA9 /* build_config.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1093,7 +1110,6 @@
824655DD0DC659B8007C2BAA /* word_iterator.cc in Sources */,
ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */,
ABF4B99E0DC2BB6000A6E319 /* clipboard.mm in Sources */,
- ABF4B9AA0DC2BC2A00A6E319 /* file_util_mac.cc in Sources */,
ABF4B9AD0DC2BC4800A6E319 /* file_version_info.mm in Sources */,
ABF4B9AF0DC2BC6200A6E319 /* json_reader.cc in Sources */,
ABF4B9B00DC2BC6500A6E319 /* json_writer.cc in Sources */,
@@ -1118,6 +1134,10 @@
E45062A60E40A9BE0025A81A /* base_switches.cc in Sources */,
E49357220E422A36008F8B09 /* timer.cc in Sources */,
E49115EF0E47B461001EE8C3 /* at_exit.cc in Sources */,
+ A5A0261F0E48FF2200498DA9 /* path_service.cc in Sources */,
+ A5A026550E4A214600498DA9 /* file_util.cc in Sources */,
+ A5A0268E0E4A2BDC00498DA9 /* file_util_posix.cc in Sources */,
+ A5A0270B0E4A630D00498DA9 /* file_util_mac.mm in Sources */,
7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
diff --git a/base/base_paths.h b/base/base_paths.h
index ba844b8..507398b 100644
--- a/base/base_paths.h
+++ b/base/base_paths.h
@@ -27,15 +27,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef BASE_BASE_PATHS_H__
-#define BASE_BASE_PATHS_H__
+#ifndef BASE_BASE_PATHS_H_
+#define BASE_BASE_PATHS_H_
// This file declares path keys for the base module. These can be used with
// the PathService to access various special directories and files.
#include "base/basictypes.h"
-#ifdef OS_WIN
+#if defined(OS_WIN)
#include "base/base_paths_win.h"
+#elif defined(OS_MACOSX)
+#include "base/base_paths_mac.h"
#endif
namespace base {
@@ -55,4 +57,4 @@ enum {
} // namespace base
-#endif // BASE_BASE_PATHS_H__
+#endif // BASE_BASE_PATHS_H_
diff --git a/base/base_paths_mac.h b/base/base_paths_mac.h
new file mode 100644
index 0000000..2097a65
--- /dev/null
+++ b/base/base_paths_mac.h
@@ -0,0 +1,54 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef BASE_BASE_PATHS_MAC_H_
+#define BASE_BASE_PATHS_MAC_H_
+
+// This file declares Mac-specific path keys for the base module.
+// These can be used with the PathService to access various special
+// directories and files.
+
+namespace base {
+
+enum {
+ PATH_MAC_START = 200,
+
+ FILE_EXE, // path and filename of the current executable
+ FILE_MODULE, // path and filename of the module containing the code for the
+ // PathService (which could differ from FILE_EXE if the
+ // PathService were compiled into a DLL, for example)
+ DIR_APP_DATA, // Application Data directory under the user profile.
+ DIR_LOCAL_APP_DATA, // "Local Settings\Application Data" directory under the
+ // user profile.
+ PATH_MAC_END
+};
+
+} // namespace base
+
+#endif // BASE_BASE_PATHS_MAC_H_
diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm
new file mode 100644
index 0000000..d5695e1
--- /dev/null
+++ b/base/base_paths_mac.mm
@@ -0,0 +1,73 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Copied from base/basictypes.h with some modifications
+
+#include "base/base_paths_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace base {
+
+bool PathProviderMac(int key, std::wstring* result) {
+ std::wstring cur;
+ switch (key) {
+ case base::FILE_EXE:
+ case base::FILE_MODULE: {
+ NSString* path = [[NSBundle mainBundle] executablePath];
+ cur = reinterpret_cast<const wchar_t*>(
+ [path cStringUsingEncoding:NSUTF32StringEncoding]);
+ break;
+ }
+ case base::DIR_APP_DATA:
+ case base::DIR_LOCAL_APP_DATA: {
+ // TODO(erikkay): maybe we should remove one of these for mac? The local
+ // vs. roaming distinction is fairly Windows-specific.
+ NSArray* dirs = NSSearchPathForDirectoriesInDomains(
+ NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ if (!dirs || [dirs count] == 0)
+ return false;
+ DCHECK([dirs count] == 1);
+ NSString* tail = [[NSString alloc] initWithCString:"Google/Chrome"];
+ NSString* path = [[dirs lastObject] stringByAppendingPathComponent:tail];
+ cur = reinterpret_cast<const wchar_t*>(
+ [path cStringUsingEncoding:NSUTF32StringEncoding]);
+ break;
+ }
+ default:
+ return false;
+ }
+
+ result->swap(cur);
+ return true;
+}
+
+} // namespace base
diff --git a/base/file_util.cc b/base/file_util.cc
index 2a29853..8ba361e 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -36,8 +36,6 @@
#include "base/string_util.h"
#include "unicode/uniset.h"
-using std::wstring;
-
namespace file_util {
const wchar_t kPathSeparator = L'\\';
@@ -55,16 +53,16 @@ void TrimTrailingSeparator(std::wstring* dir) {
void UpOneDirectory(std::wstring* dir) {
TrimTrailingSeparator(dir);
- wstring::size_type last_sep = dir->find_last_of(kPathSeparator);
- if (last_sep != wstring::npos)
+ std::wstring::size_type last_sep = dir->find_last_of(kPathSeparator);
+ if (last_sep != std::wstring::npos)
dir->resize(last_sep);
}
void UpOneDirectoryOrEmpty(std::wstring* dir) {
TrimTrailingSeparator(dir);
- wstring::size_type last_sep = dir->find_last_of(kPathSeparator);
- if (last_sep != wstring::npos)
+ std::wstring::size_type last_sep = dir->find_last_of(kPathSeparator);
+ if (last_sep != std::wstring::npos)
dir->resize(last_sep);
else
dir->clear();
@@ -74,22 +72,22 @@ void TrimFilename(std::wstring* path) {
if (EndsWithSeparator(path)) {
TrimTrailingSeparator(path);
} else {
- wstring::size_type last_sep = path->find_last_of(kPathSeparator);
- if (last_sep != wstring::npos)
+ std::wstring::size_type last_sep = path->find_last_of(kPathSeparator);
+ if (last_sep != std::wstring::npos)
path->resize(last_sep);
}
}
// TODO(mpcomplete): Make this platform-independent, etc.
-wstring GetFilenameFromPath(const wstring& path) {
- wstring::size_type pos = path.find_last_of(L"\\/");
- return wstring(path, pos == wstring::npos ? 0 : pos+1);
+std::wstring GetFilenameFromPath(const std::wstring& path) {
+ std::wstring::size_type pos = path.find_last_of(L"\\/");
+ return std::wstring(path, pos == std::wstring::npos ? 0 : pos+1);
}
-wstring GetFileExtensionFromPath(const wstring& path) {
- wstring file_name = GetFilenameFromPath(path);
- wstring::size_type last_dot = file_name.rfind(L'.');
- return wstring(last_dot == wstring::npos? L"" : file_name, last_dot+1);
+std::wstring GetFileExtensionFromPath(const std::wstring& path) {
+ std::wstring file_name = GetFilenameFromPath(path);
+ std::wstring::size_type last_dot = file_name.rfind(L'.');
+ return std::wstring(last_dot == std::wstring::npos? L"" : file_name, last_dot+1);
}
void AppendToPath(std::wstring* path, const std::wstring& new_ending) {
@@ -106,11 +104,11 @@ void AppendToPath(std::wstring* path, const std::wstring& new_ending) {
void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix) {
DCHECK(path);
- const wstring::size_type last_dot = path->rfind(kExtensionSeparator);
- const wstring::size_type last_sep = path->rfind(kPathSeparator);
+ const std::wstring::size_type last_dot = path->rfind(kExtensionSeparator);
+ const std::wstring::size_type last_sep = path->rfind(kPathSeparator);
- if (last_dot == wstring::npos ||
- (last_sep != wstring::npos && last_dot < last_sep)) {
+ if (last_dot == std::wstring::npos ||
+ (last_sep != std::wstring::npos && last_dot < last_sep)) {
// The path looks something like "C:\pics.old\jojo" or "C:\pics\jojo".
// We should just append the suffix to the entire path.
path->append(suffix);
@@ -135,7 +133,7 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
// speed.
UErrorCode status = U_ZERO_ERROR;
-#ifdef U_WCHAR_IS_UTF16
+#if defined(WCHAR_T_IS_UTF16)
UnicodeSet illegal_characters(UnicodeString(
L"[[\"*/:<>?\\\\|][:Cc:][:Cf:] - [\u200c\u200d]]"), status);
#else
@@ -158,10 +156,10 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
std::wstring::size_type i = 0;
std::wstring::size_type length = file_name->size();
-#ifdef U_WCHAR_IS_UTF16
+ const wchar_t* wstr = file_name->data();
+#if defined(WCHAR_T_IS_UTF16)
// Using |span| method of UnicodeSet might speed things up a bit, but
// it's not likely to matter here.
- const wchar_t* wstr = file_name->data();
std::wstring temp;
temp.reserve(length);
while (i < length) {
@@ -178,10 +176,10 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
}
}
file_name->swap(temp);
-#elif defined(U_WCHAR_IS_UTF32)
+#elif defined(WCHAR_T_IS_UTF32)
while (i < length) {
if (illegal_characters.contains(wstr[i])) {
- *file_name[i] = replace_char;
+ (*file_name)[i] = replace_char;
}
}
#else
@@ -190,8 +188,8 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
}
void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
- const wstring::size_type last_dot = file_name->rfind(L'.');
- wstring result = file_name->substr(0, last_dot);
+ const std::wstring::size_type last_dot = file_name->rfind(L'.');
+ std::wstring result = file_name->substr(0, last_dot);
if (!extension.empty() && extension != L".") {
if (extension.at(0) != L'.')
result.append(L".");
@@ -200,26 +198,21 @@ void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
file_name->swap(result);
}
-wstring GetDirectoryFromPath(const std::wstring& path) {
- wchar_t path_buffer[MAX_PATH];
- wchar_t* file_ptr = NULL;
- if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0)
- return L"";
-
- wstring::size_type nc = file_ptr ? file_ptr - path_buffer : path.length();
- wstring directory(path, 0, nc);
- TrimTrailingSeparator(&directory);
- return directory;
-}
-
bool ContentsEqual(const std::wstring& filename1,
const std::wstring& filename2) {
// We open the file in binary format even if they are text files because
// we are just comparing that bytes are exactly same in both files and not
// doing anything smart with text formatting.
+#if defined(OS_WIN)
std::ifstream file1(filename1.c_str(), std::ios::in | std::ios::binary);
std::ifstream file2(filename2.c_str(), std::ios::in | std::ios::binary);
-
+#elif defined(OS_POSIX)
+ std::ifstream file1(WideToUTF8(filename1).c_str(),
+ std::ios::in | std::ios::binary);
+ std::ifstream file2(WideToUTF8(filename2).c_str(),
+ std::ios::in | std::ios::binary);
+#endif
+
// Even if both files aren't openable (and thus, in some sense, "equal"),
// any unusable file yields a result of "false".
if (!file1.is_open() || !file2.is_open())
@@ -247,10 +240,16 @@ bool ContentsEqual(const std::wstring& filename1,
}
bool ReadFileToString(const std::wstring& path, std::string* contents) {
+#if defined(OS_WIN)
FILE* file;
errno_t err = _wfopen_s(&file, path.c_str(), L"rbS");
if (err != 0)
return false;
+#elif defined(OS_POSIX)
+ FILE* file = fopen(WideToUTF8(path).c_str(), "r");
+ if (!file)
+ return false;
+#endif
char buf[1 << 16];
size_t len;
diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc
new file mode 100644
index 0000000..324b818
--- /dev/null
+++ b/base/file_util_linux.cc
@@ -0,0 +1,55 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Copied from base/basictypes.h with some modifications
+
+#include "base/file_util.h"
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace file_util {
+
+bool GetTempDir(std::wstring* path) {
+ const char* tmp = getenv("TMPDIR");
+ if (tmp)
+ *path = UTF8ToWide(tmp);
+ else
+ *path = L"/tmp";
+ return true;
+}
+
+bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
+ // TODO(erikkay): implement
+ DCHECK(false);
+ return false;
+}
+
+} // namespace file_util
diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
new file mode 100644
index 0000000..f51ef38
--- /dev/null
+++ b/base/file_util_mac.mm
@@ -0,0 +1,55 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Copied from base/basictypes.h with some modifications
+
+#include "base/file_util.h"
+
+#import <Cocoa/Cocoa.h>
+#include <copyfile.h>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace file_util {
+
+bool GetTempDir(std::wstring* path) {
+ NSString* tmp = NSTemporaryDirectory();
+ if (tmp == nil)
+ return false;
+ *path = reinterpret_cast<const wchar_t*>(
+ [tmp cStringUsingEncoding:NSUTF32StringEncoding]);
+ return true;
+}
+
+bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
+ return (copyfile(WideToUTF8(from_path).c_str(),
+ WideToUTF8(to_path).c_str(), NULL, COPYFILE_ALL) == 0);
+}
+
+} // namespace
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
new file mode 100644
index 0000000..a413e87
--- /dev/null
+++ b/base/file_util_posix.cc
@@ -0,0 +1,299 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Copied from base/basictypes.h with some modifications
+
+#include "base/file_util.h"
+
+#include <sys/stat.h>
+#include <sys/syslimits.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <time.h>
+
+#include <fstream>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace file_util {
+
+std::wstring GetDirectoryFromPath(const std::wstring& path) {
+ char full_path[PATH_MAX];
+#if defined(OS_MACOSX)
+ strlcpy(full_path, WideToUTF8(path).c_str(), sizeof(full_path));
+#elif defined(OS_LINUX)
+ std::string utf8_path = WideToUTF8(path);
+ const char* cstr = utf8_path.c_str();
+ strncpy(full_path, cstr, PATH_MAX);
+ cstr[PATH_MAX - 1] = '\0';
+#endif
+ return UTF8ToWide(dirname(full_path));
+}
+
+bool Delete(const std::wstring& path, bool recursive) {
+ std::string utf8_path = WideToUTF8(path);
+ struct stat64 file_info;
+ if (stat64(utf8_path.c_str(), &file_info) != 0);
+ return false;
+ if (!S_ISDIR(file_info.st_mode))
+ return (unlink(utf8_path.c_str()) == 0);
+ if (!recursive)
+ return (rmdir(utf8_path.c_str()) == 0);
+
+ // TODO(erikkay): delete directories
+ DCHECK(recursive);
+ return false;
+}
+
+bool Move(const std::wstring& from_path, const std::wstring& to_path) {
+ return (rename(WideToUTF8(from_path).c_str(),
+ WideToUTF8(to_path).c_str()) == 0);
+}
+
+bool CopyTree(const std::wstring& from_path, const std::wstring& to_path) {
+ // TODO(erikkay): implement
+ return false;
+}
+
+bool PathExists(const std::wstring& path) {
+ struct stat64 file_info;
+ return (stat64(WideToUTF8(path).c_str(), &file_info) == 0);
+}
+
+// TODO(erikkay): implement
+#if 0
+bool GetFileCreationLocalTimeFromHandle(int fd,
+ LPSYSTEMTIME creation_time) {
+ if (!file_handle)
+ return false;
+
+ FILETIME utc_filetime;
+ if (!GetFileTime(file_handle, &utc_filetime, NULL, NULL))
+ return false;
+
+ FILETIME local_filetime;
+ if (!FileTimeToLocalFileTime(&utc_filetime, &local_filetime))
+ return false;
+
+ return !!FileTimeToSystemTime(&local_filetime, creation_time);
+}
+
+bool GetFileCreationLocalTime(const std::string& filename,
+ LPSYSTEMTIME creation_time) {
+ ScopedHandle file_handle(
+ CreateFile(filename.c_str(), GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
+ return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time);
+}
+#endif
+
+bool ResolveShortcut(std::wstring* path) {
+ char full_path[PATH_MAX];
+ if (!realpath(WideToUTF8(*path).c_str(), full_path))
+ return false;
+ *path = UTF8ToWide(full_path);
+ return true;
+}
+
+bool CreateShortcutLink(const char *source, const char *destination,
+ const char *working_dir, const char *arguments,
+ const char *description, const char *icon,
+ int icon_index) {
+ // TODO(erikkay): implement
+ return false;
+}
+
+bool CreateTemporaryFileName(std::wstring* temp_file) {
+ std::wstring tmpdir;
+ if (!GetTempDir(&tmpdir))
+ return false;
+ tmpdir.append(L"/com.google.chrome.XXXXXX");
+ // this should be OK since mktemp just replaces characters in place
+ char* buffer = const_cast<char*>(WideToUTF8(tmpdir).c_str());
+ *temp_file = UTF8ToWide(mktemp(buffer));
+ return true;
+}
+
+bool CreateNewTempDirectory(const std::wstring& prefix,
+ std::wstring* new_temp_path) {
+ std::wstring tmpdir;
+ if (!GetTempDir(&tmpdir))
+ return false;
+ tmpdir.append(L"/com.google.chrome.XXXXXX");
+ // this should be OK since mkdtemp just replaces characters in place
+ char* buffer = const_cast<char*>(WideToUTF8(tmpdir).c_str());
+ char* dtemp = mkdtemp(buffer);
+ if (!dtemp)
+ return false;
+ *new_temp_path = UTF8ToWide(dtemp);
+ return true;
+}
+
+bool CreateDirectory(const std::wstring& full_path) {
+ return (mkdir(WideToUTF8(full_path).c_str(), 0777) == 0);
+}
+
+bool GetFileSize(const std::wstring& file_path, int64* file_size) {
+ struct stat64 file_info;
+ if (stat64(WideToUTF8(file_path).c_str(), &file_info) != 0)
+ return false;
+ *file_size = file_info.st_size;
+ return true;
+}
+
+int ReadFile(const std::wstring& filename, char* data, int size) {
+ int fd = open(WideToUTF8(filename).c_str(), O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ int ret_value = read(fd, data, size);
+ close(fd);
+ return ret_value;
+}
+
+int WriteFile(const std::wstring& filename, const char* data, int size) {
+ int fd = open(WideToUTF8(filename).c_str(), O_WRONLY | O_CREAT | O_TRUNC,
+ 0666);
+ if (fd < 0)
+ return -1;
+
+ int ret_value = write(fd, data, size);
+ close(fd);
+ return ret_value;
+}
+
+// Gets the current working directory for the process.
+bool GetCurrentDirectory(std::wstring* dir) {
+ char system_buffer[PATH_MAX] = "";
+ getcwd(system_buffer, sizeof(system_buffer));
+ *dir = UTF8ToWide(system_buffer);
+ return true;
+}
+
+// Sets the current working directory for the process.
+bool SetCurrentDirectory(const std::wstring& current_directory) {
+ int ret = chdir(WideToUTF8(current_directory).c_str());
+ return (ret == 0);
+}
+
+// TODO(erikkay): implement
+#if 0
+FileEnumerator::FileEnumerator(const std::string& root_path,
+ bool recursive,
+ FileEnumerator::FILE_TYPE file_type)
+ : recursive_(recursive),
+ file_type_(file_type),
+ is_in_find_op_(false),
+ find_handle_(INVALID_HANDLE_VALUE) {
+ pending_paths_.push(root_path);
+}
+
+FileEnumerator::FileEnumerator(const std::string& root_path,
+ bool recursive,
+ FileEnumerator::FILE_TYPE file_type,
+ const std::string& pattern)
+ : recursive_(recursive),
+ file_type_(file_type),
+ is_in_find_op_(false),
+ pattern_(pattern),
+ find_handle_(INVALID_HANDLE_VALUE) {
+ pending_paths_.push(root_path);
+}
+
+FileEnumerator::~FileEnumerator() {
+ if (find_handle_ != INVALID_HANDLE_VALUE)
+ FindClose(find_handle_);
+}
+
+std::wstring FileEnumerator::Next() {
+ if (!is_in_find_op_) {
+ if (pending_paths_.empty())
+ return std::wstring();
+
+ // The last find FindFirstFile operation is done, prepare a new one.
+ // root_path_ must have the trailing directory character.
+ root_path_ = pending_paths_.top();
+ file_util::AppendToPath(&root_path_, std::wstring());
+ pending_paths_.pop();
+
+ // Start a new find operation.
+ std::wstring src(root_path_);
+
+ if (pattern_.empty())
+ file_util::AppendToPath(&src, "*"); // No pattern = match everything.
+ else
+ file_util::AppendToPath(&src, pattern_);
+
+ find_handle_ = FindFirstFile(src.c_str(), &find_data_);
+ is_in_find_op_ = true;
+
+ } else {
+ // Search for the next file/directory.
+ if (!FindNextFile(find_handle_, &find_data_)) {
+ FindClose(find_handle_);
+ find_handle_ = INVALID_HANDLE_VALUE;
+ }
+ }
+
+ if (INVALID_HANDLE_VALUE == find_handle_) {
+ is_in_find_op_ = false;
+
+ // This is reached when we have finished a directory and are advancing to
+ // the next one in the queue. We applied the pattern (if any) to the files
+ // in the root search directory, but for those directories which were
+ // matched, we want to enumerate all files inside them. This will happen
+ // when the handle is empty.
+ pattern_.clear();
+
+ return Next();
+ }
+
+ std::wstring cur_file(find_data_.cFileName);
+ // Skip over . and ..
+ if (L"." == cur_file || L".." == cur_file)
+ return Next();
+
+ // Construct the absolute filename.
+ cur_file.insert(0, root_path_);
+
+ if (recursive_ && find_data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ // If |cur_file| is a directory, and we are doing recursive searching, add
+ // it to pending_paths_ so we scan it after we finish scanning this
+ // directory.
+ pending_paths_.push(cur_file);
+ return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
+ }
+ return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
+}
+#endif
+
+
+} // namespace file_util
+
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index a9d0b0b..251d030 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -42,6 +42,19 @@
namespace file_util {
+std::wstring GetDirectoryFromPath(const std::wstring& path) {
+ wchar_t path_buffer[MAX_PATH];
+ wchar_t* file_ptr = NULL;
+ if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0)
+ return L"";
+
+ std::wstring::size_type length =
+ file_ptr ? file_ptr - path_buffer : path.length();
+ std::wstring directory(path, 0, length);
+ TrimTrailingSeparator(&directory);
+ return directory;
+}
+
int CountFilesCreatedAfter(const std::wstring& path,
const FILETIME& comparison_time) {
int file_count = 0;
@@ -644,4 +657,4 @@ std::wstring FileEnumerator::Next() {
return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
}
-} // namespace
+} // namespace file_util
diff --git a/base/path_service.cc b/base/path_service.cc
index 12073f7..8205b03 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -43,8 +43,10 @@
namespace base {
bool PathProvider(int key, std::wstring* result);
-#ifdef OS_WIN
+#if defined(OS_WIN)
bool PathProviderWin(int key, std::wstring* result);
+#elif defined (OS_MACOSX)
+ bool PathProviderMac(int key, std::wstring* ressult);
#endif
}
@@ -84,6 +86,18 @@ static Provider base_provider_win = {
};
#endif
+#ifdef OS_MACOSX
+ static Provider base_provider_mac = {
+ base::PathProviderMac,
+ &base_provider,
+#ifndef NDEBUG
+ base::PATH_MAC_START,
+ base::PATH_MAC_END
+#endif
+ };
+#endif
+
+
struct PathData {
Lock lock;
PathMap cache; // Track mappings from path key to path value.
@@ -93,7 +107,9 @@ struct PathData {
PathData() {
#if defined(OS_WIN)
providers = &base_provider_win;
-#elif defined(OS_POSIX)
+#elif defined(OS_MACOSX)
+ providers = &base_provider_mac;
+#elif defined(OS_LINUX)
providers = &base_provider;
#endif
}
@@ -115,17 +131,8 @@ bool PathService::Get(int key, std::wstring* result) {
DCHECK(key >= base::DIR_CURRENT);
// special case the current directory because it can never be cached
- if (key == base::DIR_CURRENT) {
-#if defined(OS_WIN)
+ if (key == base::DIR_CURRENT)
return file_util::GetCurrentDirectory(result);
-#elif defined(OS_POSIX)
- char system_buffer[PATH_MAX];
- system_buffer[0] = 0;
- getcwd(system_buffer, sizeof(system_buffer));
- *result = NativeMBToWide(system_buffer);
- return true;
-#endif
- }
// TODO(darin): it would be nice to avoid holding this lock while calling out
// to the path providers.
@@ -170,6 +177,7 @@ bool PathService::Override(int key, const std::wstring& path) {
DCHECK(path_data);
DCHECK(key > base::DIR_CURRENT) << "invalid path key";
+ // TODO(erikkay): pull this into file_util*
#if defined(OS_WIN)
wchar_t file_path_buf[MAX_PATH];
if (!_wfullpath(file_path_buf, path.c_str(), MAX_PATH))
@@ -202,12 +210,7 @@ bool PathService::Override(int key, const std::wstring& path) {
}
bool PathService::SetCurrentDirectory(const std::wstring& current_directory) {
-#if defined(OS_WIN)
return file_util::SetCurrentDirectory(current_directory);
-#elif defined(OS_POSIX)
- int ret = chdir(WideToNativeMB(current_directory).c_str());
- return (ret == 0);
-#endif
}
void PathService::RegisterProvider(ProviderFunc func, int key_start,