Make PostList subclasses return PostList* not Internal*
[xapian.git] / xapian-applications / omega / tmpdir.h
blob8578de5515bbae91c47829997f1e7434ee50f6a9
1 /** @file tmpdir.h
2 * @brief create a temporary directory securely
3 */
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
24 #include <string>
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
39 * string.
41 inline std::string get_tmpfile(const char * leaf) {
42 std::string f = get_tmpdir();
43 if (!f.empty())
44 f += leaf;
45 return f;
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
53 * string.
55 inline std::string get_tmpfile(const std::string & leaf) {
56 std::string f = get_tmpdir();
57 if (!f.empty())
58 f += leaf;
59 return f;
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
66 * won't get removed.
68 void remove_tmpdir();
70 #endif // OMEGA_INCLUDED_TMPDIR_H