summaryrefslogtreecommitdiffabout
path: root/src/util.cc
Unidiff
Diffstat (limited to 'src/util.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/util.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
new file mode 100644
index 0000000..afb2641
--- a/dev/null
+++ b/src/util.cc
@@ -0,0 +1,21 @@
1#include <unistd.h>
2#include <fstream>
3#include <stdexcept>
4using namespace std;
5#include "util.h"
6
7void pid_file::set(const string& f,bool u) {
8 ofstream of(f.c_str(),ios::trunc);
9 if(!of)
10 throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to open file for writing pid");
11 of << getpid() << endl;
12 of.close();
13 file_name = f;
14 unlink_pid = u;
15}
16void pid_file::unlink() {
17 if(!unlink_pid)
18 return;
19 ::unlink(file_name.c_str());
20}
21