[llvm] r216460 - Merge TempDir and system_temp_directory.

Timur Iskhodzhanov timurrrr at google.com
Wed Aug 27 02:35:32 PDT 2014


Hi Rafael,

This change has introduced a warning:
llvm/lib/Support/Unix/Path.inc:666:7: error: implicit conversion turns
string literal into bool: 'const char [5]' to 'bool'
[-Werror,-Wstring-conversion]

Mind taking a look?
Since the change seems to be just cleanup, I'll just revert it so you
can take a look offline.

--
Tim

2014-08-26 18:47 GMT+04:00 Rafael Espindola <rafael.espindola at gmail.com>:
> Modified: llvm/trunk/lib/Support/Unix/Path.inc
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=216460&r1=216459&r2=216460&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Unix/Path.inc (original)
> +++ llvm/trunk/lib/Support/Unix/Path.inc Tue Aug 26 09:47:52 2014
> @@ -87,22 +87,6 @@ namespace {
>    };
>  }
>
> -static std::error_code TempDir(SmallVectorImpl<char> &result) {
> -  // FIXME: Don't use TMPDIR if program is SUID or SGID enabled.
> -  const char *dir = nullptr;
> -  (dir = std::getenv("TMPDIR")) || (dir = std::getenv("TMP")) ||
> -      (dir = std::getenv("TEMP")) || (dir = std::getenv("TEMPDIR")) ||
> -#ifdef P_tmpdir
> -      (dir = P_tmpdir) ||
> -#endif
> -      (dir = "/tmp");
> -
> -  result.clear();
> -  StringRef d(dir);
> -  result.append(d.begin(), d.end());
> -  return std::error_code();
> -}
> -
>  namespace llvm {
>  namespace sys  {
>  namespace fs {
> @@ -665,6 +649,66 @@ bool home_directory(SmallVectorImpl<char
>    return false;
>  }
>
> +static const char *getEnvTempDir() {
> +  // Check whether the temporary directory is specified by an environment
> +  // variable.
> +  const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
> +  for (const char *Env : EnvironmentVariables) {
> +    if (const char *Dir = std::getenv(Env))
> +      return Dir;
> +  }
> +
> +  return nullptr;
> +}
> +
> +static const char *getDefaultTempDir(bool ErasedOnReboot) {
> +#ifdef P_tmpdir
> +  if (P_tmpdir)
> +    return P_tmpdir;
> +#endif
> +
> +  if (ErasedOnReboot)
> +    return "/tmp";
> +  return "/var/tmp";
> +}
> +
> +void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) {
> +  Result.clear();
> +
> +  if (ErasedOnReboot) {
> +    // There is no env variable for the cache directory.
> +    if (const char *RequestedDir = getEnvTempDir()) {
> +      Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
> +      return;
> +    }
> +  }
> +
> +#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
> +  // On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR.
> +  // macros defined in <unistd.h> on darwin >= 9
> +  int ConfName = ErasedOnReboot? _CS_DARWIN_USER_TEMP_DIR
> +                               : _CS_DARWIN_USER_CACHE_DIR;
> +  size_t ConfLen = confstr(ConfName, nullptr, 0);
> +  if (ConfLen > 0) {
> +    do {
> +      Result.resize(ConfLen);
> +      ConfLen = confstr(ConfName, Result.data(), Result.size());
> +    } while (ConfLen > 0 && ConfLen != Result.size());
> +
> +    if (ConfLen > 0) {
> +      assert(Result.back() == 0);
> +      Result.pop_back();
> +      return;
> +    }
> +
> +    Result.clear();
> +  }
> +#endif
> +
> +  const char *RequestedDir = getDefaultTempDir(ErasedOnReboot);
> +  Result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
> +}
> +
>  } // end namespace path
>
>  } // end namespace sys



More information about the llvm-commits mailing list