]> git.sesse.net Git - cubemap/blob - util.h
Fix a segfault on reload introduced by the pacing changes.
[cubemap] / util.h
1 #ifndef _UTIL_H
2 #define _UTIL_H
3
4 // Some utilities for reading and writing to temporary files.
5
6 #include <string>
7
8 // Make a file in /tmp, unlink it, and write <contents> to it.
9 // Returns the opened file descriptor, or -1 on failure.
10 int make_tempfile(const std::string &contents);
11
12 // Opposite of make_tempfile(). Returns false on failure.
13 bool read_tempfile_and_close(int fd, std::string *contents);
14
15 // Same as read_tempfile_and_close(), without the close.
16 bool read_tempfile(int fd, std::string *contents);
17
18 // Close a file descriptor, taking care of EINTR on the way.
19 // log_perror() if it fails; apart from that, behaves as close().
20 int safe_close(int fd);
21
22 #endif  // !defined(_UTIL_H