Chromium Code Reviews

Side by Side Diff: chrome/browser/sync/util/path_helpers_posix.cc

Issue 211019: Fix compiling of sync on linux. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <pwd.h> 5 #include <pwd.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "chrome/browser/sync/notifier/base/string.h"
8 #include "chrome/browser/sync/util/path_helpers.h" 9 #include "chrome/browser/sync/util/path_helpers.h"
9 10
10 #if ((!defined(OS_LINUX)) && (!defined(OS_MACOSX))) 11 #if ((!defined(OS_LINUX)) && (!defined(OS_MACOSX)))
11 #error Compile this file on Mac OS X or Linux only. 12 #error Compile this file on Mac OS X or Linux only.
12 #endif 13 #endif
13 14
14 PathString ExpandTilde(const PathString& path) { 15 PathString ExpandTilde(const PathString& path) {
15 if (path.empty()) 16 if (path.empty())
16 return path; 17 return path;
17 if ('~' != path[0]) 18 if ('~' != path[0])
18 return path; 19 return path;
19 PathString ret; 20 PathString ret;
20 // TODO(sync): Consider using getpwuid_r. 21 // TODO(sync): Consider using getpwuid_r.
21 ret.insert(0, getpwuid(getuid())->pw_dir); 22 ret.insert(0, getpwuid(getuid())->pw_dir);
22 ret.append(++path.begin(), path.end()); 23 ret.append(++path.begin(), path.end());
23 return ret; 24 return ret;
24 } 25 }
25 26
26 namespace { 27 namespace {
27 // TODO(sync): We really should use char[]. 28 // TODO(sync): We really should use char[].
28 string cache_dir_; 29 std::string cache_dir_;
29 } 30 }
30 31
31 void set_cache_dir(string cache_dir) { 32 void set_cache_dir(std::string cache_dir) {
32 CHECK(cache_dir_.empty()); 33 CHECK(cache_dir_.empty());
33 cache_dir_ = cache_dir; 34 cache_dir_ = cache_dir;
34 } 35 }
35 36
36 string get_cache_dir() { 37 std::string get_cache_dir() {
37 CHECK(!cache_dir_.empty()); 38 CHECK(!cache_dir_.empty());
38 return cache_dir_; 39 return cache_dir_;
39 } 40 }
40 41
41 // On Posix, PathStrings are UTF-8, not UTF-16 as they are on Windows. Thus, 42 // On Posix, PathStrings are UTF-8, not UTF-16 as they are on Windows. Thus,
42 // this function is different from the Windows version. 43 // this function is different from the Windows version.
43 PathString TruncatePathString(const PathString& original, int length) { 44 PathString TruncatePathString(const PathString& original, int length) {
44 if (original.size() <= length) 45 if (original.size() <= static_cast<size_t>(length))
45 return original; 46 return original;
46 if (length <= 0) 47 if (length <= 0)
47 return original; 48 return original;
48 PathString ret(original.begin(), original.begin() + length); 49 PathString ret(original.begin(), original.begin() + length);
49 COMPILE_ASSERT(sizeof(PathChar) == sizeof(uint8), PathStringNotUTF8); 50 COMPILE_ASSERT(sizeof(PathChar) == sizeof(uint8), PathStringNotUTF8);
50 PathString::reverse_iterator last_char = ret.rbegin(); 51 PathString::reverse_iterator last_char = ret.rbegin();
51 52
52 // Values taken from 53 // Values taken from
53 // http://en.wikipedia.org/w/index.php?title=UTF-8&oldid=252875566 54 // http://en.wikipedia.org/w/index.php?title=UTF-8&oldid=252875566
54 if (0 == (*last_char & 0x80)) 55 if (0 == (*last_char & 0x80))
(...skipping 27 matching lines...)
82 83
83 // Invalid utf-8. chop off last "codepoint" and return. 84 // Invalid utf-8. chop off last "codepoint" and return.
84 ret.resize(ret.size() - last_codepoint_len); 85 ret.resize(ret.size() - last_codepoint_len);
85 return ret; 86 return ret;
86 } 87 }
87 88
88 // Convert /s to :s. 89 // Convert /s to :s.
89 PathString MakePathComponentOSLegal(const PathString& component) { 90 PathString MakePathComponentOSLegal(const PathString& component) {
90 if (PathString::npos == component.find("/")) 91 if (PathString::npos == component.find("/"))
91 return PSTR(""); 92 return PSTR("");
92 PathString new_name; 93 PathString new_name(component);
93 new_name.reserve(component.size()); 94 notifier::StringReplace(&new_name, "/", ":", true);
94 StringReplace(component, "/", ":", true, &new_name);
95 return new_name; 95 return new_name;
96 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/path_helpers_linux.cc ('k') | chrome/browser/sync/util/pthread_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine