ALPSCore reference
temporary_filename.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
8 #include <cstdlib>
9 
10 namespace alps {
11  std::string temporary_filename(const std::string& prefix)
12  {
13  std::string dir="";
14  if (prefix.find('/')==prefix.npos) {
15  const char* tmpdir=std::getenv("TMPDIR");
16  if (tmpdir!=nullptr && tmpdir[0]!=0) {
17  dir.assign(tmpdir);
18  dir.append("/");
19  } else {
20  dir.assign("/tmp/");
21  }
22  }
24  }
25 }
const std::string & name() const
Returns temporary file name.
Definition: unique_file.hpp:38
Resource manager: manages a file with unique name.
Definition: unique_file.hpp:17
std::string temporary_filename(const std::string &prefix)
Generate a reasonably unique file name with a given prefix.
Remove the file after constructing the object only.
Definition: unique_file.hpp:23