2 * @brief create a temporary directory securely
4 /* Copyright (C) 2011,2014 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef OMEGA_INCLUDED_TMPDIR_H
22 #define OMEGA_INCLUDED_TMPDIR_H
26 /** Return path to temporary directory.
28 * If successfully called before, this just returns the same path.
30 * @return If successful, path to directory; otherwise empty string.
32 const std::string
& get_tmpdir();
34 /** Return temporary filename with specified leaf.
36 * The filename will be in a securely created temporary directory.
38 * @return If successful, filename with specified leaf; otherwise empty
41 inline std::string
get_tmpfile(const char * leaf
) {
42 std::string f
= get_tmpdir();
48 /** Return temporary filename with specified leaf.
50 * The filename will be in a securely created temporary directory.
52 * @return If successful, filename with specified leaf; otherwise empty
55 inline std::string
get_tmpfile(const std::string
& leaf
) {
56 std::string f
= get_tmpdir();
62 /** Attempt to remove the directory if we created one.
64 * If get_tmpdir() hasn't been called or hasn't succeeded, does nothing.
65 * If the directory isn't empty or rmdir() otherwise fails, the directory
70 #endif // OMEGA_INCLUDED_TMPDIR_H