summaryrefslogtreecommitdiffabout
path: root/src/util.cc
authorMichael Krelin <hacker@klever.net>2004-07-09 16:48:52 (UTC)
committer Michael Krelin <hacker@klever.net>2004-07-09 16:48:52 (UTC)
commit9148dac885c0325636c2d33715ba248371706d0d (patch) (unidiff)
treefd95d60f6fd051c3ad46a966882e2be48440452f /src/util.cc
downloaddudki-9148dac885c0325636c2d33715ba248371706d0d.zip
dudki-9148dac885c0325636c2d33715ba248371706d0d.tar.gz
dudki-9148dac885c0325636c2d33715ba248371706d0d.tar.bz2
dudki: initial import into svn repository
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