Boost logo

Boost :

Subject: [boost] [filesystem] temp_dir_path()
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-10-09 12:36:23

The need for portably obtaining 'the' temporary-directory-path has been
brought up a few times(but never addressed AFAICT), and I am now in the
need for this as well.

Windows has the GetTempPath, which follows a specific order of looking
for a temporary directory path. If GetTempPath returns 0, GetLastError
provides a system error.

Posix relies on getEnv("TMPDIR"), which returns 0 if the environment
variable does not exist.

The following windows and posix implementation would be in the detail

   path temp_dir_path(system::error_code* ec)
       const char* val = getenv("TMPDIR");
       return val? path(val) : path();

# else // Windows

       std::vector<Path::value_type> buf(GetTempPathW(0, NULL));

       if(GetTempPathW(buf.size(), &buf[0]))
           return path(buf.begin(), buf.end());

       int errval(::GetLastError());
       if (ec)
           ec->assign(errval, system_category());

       return path()
# endif

- should Posix return an empty path or an error when empty?
- should Windows provide a more 'temp-path' centric error?
- should both verify the path exists?
- if the path does not exist should one be created?

Thanks, Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at