From 85a14794c812859d9fe30a5a7e9fd0e3471e7882 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 6 Feb 2014 01:19:13 +0100 Subject: [PATCH] Expand environment variables before checking existence of file and directory. --- src/support/GTools.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/support/GTools.cpp b/src/support/GTools.cpp index 6d5c653..1adef9e 100644 --- a/src/support/GTools.cpp +++ b/src/support/GTools.cpp @@ -855,7 +855,8 @@ double gammalib::plaw_energy_flux(const double& emin, const double& emax, * @param[in] filename File name. * * Checks if a file exists. If a directory with the same name if found, false - * is returned. + * is returned. The function expands any environment variable prior to + * checking. ***************************************************************************/ bool gammalib::file_exists(const std::string& filename) { @@ -866,7 +867,7 @@ bool gammalib::file_exists(const std::string& filename) struct stat info; // Get file information structure - int ret = stat(filename.c_str(), &info); + int ret = stat(gammalib::expand_env(filename).c_str(), &info); // Check if file is a regular file if (ret == 0 && S_ISREG(info.st_mode)) { @@ -883,7 +884,8 @@ bool gammalib::file_exists(const std::string& filename) * * @param[in] dirname Directory name. * - * Checks if a directory exists. + * Checks if a directory exists. The function expands any environment + * variable prior to checking. ***************************************************************************/ bool gammalib::dir_exists(const std::string& dirname) { @@ -894,7 +896,7 @@ bool gammalib::dir_exists(const std::string& dirname) struct stat info; // Get file information structure - int ret = stat(dirname.c_str(), &info); + int ret = stat(gammalib::expand_env(dirname).c_str(), &info); // Check if we have a directory if (ret == 0 && S_ISDIR(info.st_mode)) { -- libgit2 0.21.4