std::string PathForResource()

in storage/testapp/src/desktop/desktop_main.cc [78:108]


std::string PathForResource() {
#if defined(_WIN32)
  // On Windows we should hvae TEST_TMPDIR or TEMP or TMP set.
  char buf[MAX_PATH + 1];
  if (GetEnvironmentVariable("TEST_TMPDIR", buf, sizeof(buf)) ||
      GetEnvironmentVariable("TEMP", buf, sizeof(buf)) ||
      GetEnvironmentVariable("TMP", buf, sizeof(buf))) {
    std::string path(buf);
    // Add trailing slash.
    if (path[path.size() - 1] != '\\') path += '\\';
    return path;
  }
#else
  // Linux and OS X should either have the TEST_TMPDIR environment variable set
  // or use /tmp.
  if (const char* value = getenv("TEST_TMPDIR")) {
    std::string path(value);
    // Add trailing slash.
    if (path[path.size() - 1] != '/') path += '/';
    return path;
  }
  struct stat s;
  if (stat("/tmp", &s) == 0) {
    if (s.st_mode & S_IFDIR) {
      return std::string("/tmp/");
    }
  }
#endif  // defined(_WIN32)
  // If nothing else, use the current directory.
  return std::string();
}