Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost filesystem get_temporary_file()
From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2009-07-18 03:11:29


> > I cannot find any function in the Boost.Filesystem library to get a
> > temporary filename. There has been some discussion about this
functionality
> > on the lists many years ago - did anything come of this? I need a
> > cross-platform way to do this and was hoping boost would provide it :)
>
> I was looking for exactly such a thing just yesterday and was surprised to
> find that boost::filesystem didn't have one. Here's the function I wrote
> instead (Windows only) in case it's of any use:
>
> wpath TempFilePath()
> {
> vector<wchar_t> buffer(MAX_PATH);
> DWORD len = ::GetTempPath(buffer.size(), &buffer[0]);
>
> wstring directory(&buffer[0], buffer.size());
>
> if (!GetTempFileName(directory.c_str(), NULL, 0, &buffer[0]))
> throw boost::system::system_error(
> ::GetLastError(), boost::system::system_category);
>
> wstring file(&buffer[0], buffer.size());
>
> return wpath(directory) / file;
> }

Thanks Alex. I have a similar function for Win32 as this is my primary
platform.

How should this be implemented for Linux with the same semantics and
guarantees?

Regards
-- Craig


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net