diff options
Diffstat (limited to 'base/nix')
-rw-r--r-- | base/nix/xdg_util.cc | 20 | ||||
-rw-r--r-- | base/nix/xdg_util.h | 4 |
2 files changed, 15 insertions, 9 deletions
diff --git a/base/nix/xdg_util.cc b/base/nix/xdg_util.cc index c59578d..7d26344 100644 --- a/base/nix/xdg_util.cc +++ b/base/nix/xdg_util.cc @@ -4,6 +4,8 @@ #include "base/nix/xdg_util.h" +#include <string> + #include "base/environment.h" #include "base/file_path.h" #include "base/file_util.h" @@ -14,21 +16,25 @@ namespace nix { FilePath GetXDGDirectory(Environment* env, const char* env_name, const char* fallback_dir) { + FilePath path; std::string env_value; if (env->GetVar(env_name, &env_value) && !env_value.empty()) - return FilePath(env_value); - return file_util::GetHomeDir().Append(fallback_dir); + path = FilePath(env_value); + else + path = file_util::GetHomeDir().Append(fallback_dir); + return path.StripTrailingSeparators(); } -FilePath GetXDGUserDirectory(Environment* env, const char* dir_name, - const char* fallback_dir) { +FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) { + FilePath path; char* xdg_dir = xdg_user_dir_lookup(dir_name); if (xdg_dir) { - FilePath path(xdg_dir); + path = FilePath(xdg_dir); free(xdg_dir); - return path.StripTrailingSeparators(); + } else { + path = file_util::GetHomeDir().Append(fallback_dir); } - return file_util::GetHomeDir().Append(fallback_dir); + return path.StripTrailingSeparators(); } DesktopEnvironment GetDesktopEnvironment(Environment* env) { diff --git a/base/nix/xdg_util.h b/base/nix/xdg_util.h index 305a679..cb8072ce 100644 --- a/base/nix/xdg_util.h +++ b/base/nix/xdg_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -38,7 +38,7 @@ BASE_EXPORT FilePath GetXDGDirectory(Environment* env, const char* env_name, // Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs // This looks up "well known" user directories like the desktop and music // folder. Examples of |dir_name| are DESKTOP and MUSIC. -BASE_EXPORT FilePath GetXDGUserDirectory(Environment* env, const char* dir_name, +BASE_EXPORT FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir); enum DesktopEnvironment { |