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

Side by Side Diff: base/base_paths_mac.mm

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | « no previous file | base/rand_util.h » ('j') | crypto/encryptor_mac.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base_paths_mac.h" 5 #include "base/base_paths_mac.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <mach-o/dyld.h> 9 #include <mach-o/dyld.h>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/foundation_util.h" 15 #include "base/mac/foundation_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 18
19 namespace { 19 namespace {
20 20
21 bool GetNSExecutablePath(FilePath* path) WARN_UNUSED_RESULT; 21 bool GetNSExecutablePath(FilePath* path) WARN_UNUSED_RESULT;
22 22
23 bool GetNSExecutablePath(FilePath* path) { 23 bool GetNSExecutablePath(FilePath* path) {
24 DCHECK(path); 24 DCHECK(path);
25 // Executable path can have relative references ("..") depending on 25 // Executable path can have relative references ("..") depending on
26 // how the app was launched. 26 // how the app was launched.
27 uint32_t executable_length = 0; 27 uint32_t executable_length = 0;
28 _NSGetExecutablePath(NULL, &executable_length); 28 _NSGetExecutablePath(NULL, &executable_length);
29 DCHECK_GE(executable_length, 1u); 29 DCHECK_GT(executable_length, 1u);
30 std::string executable_path; 30 std::string executable_path;
31 char* executable_path_c = WriteInto(&executable_path, executable_length); 31 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length),
32 int rv = _NSGetExecutablePath(executable_path_c, &executable_length); 32 &executable_length);
33 DCHECK_EQ(rv, 0); 33 DCHECK_EQ(rv, 0);
34 DCHECK(!executable_path.empty());
35 if ((rv != 0) || (executable_path.empty()))
36 return false;
37 *path = FilePath(executable_path); 34 *path = FilePath(executable_path);
38 return true; 35 return true;
39 } 36 }
40 37
41 // Returns true if the module for |address| is found. |path| will contain 38 // Returns true if the module for |address| is found. |path| will contain
42 // the path to the module. Note that |path| may not be absolute. 39 // the path to the module. Note that |path| may not be absolute.
43 bool GetModulePathForAddress(FilePath* path, 40 bool GetModulePathForAddress(FilePath* path,
44 const void* address) WARN_UNUSED_RESULT; 41 const void* address) WARN_UNUSED_RESULT;
45 42
46 bool GetModulePathForAddress(FilePath* path, const void* address) { 43 bool GetModulePathForAddress(FilePath* path, const void* address) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 *result = result->DirName().DirName(); 81 *result = result->DirName().DirName();
85 } 82 }
86 return true; 83 return true;
87 } 84 }
88 default: 85 default:
89 return false; 86 return false;
90 } 87 }
91 } 88 }
92 89
93 } // namespace base 90 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/rand_util.h » ('j') | crypto/encryptor_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698