summaryrefslogtreecommitdiff
path: root/src/common/lock.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2012-12-27 21:23:46 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-01-07 15:31:38 -0800
commitc080e504e4d74027b985b1ed675c172c083cea76 (patch)
treeac084d16d9d40c0a0c950b66eb62a0e16795d486 /src/common/lock.cpp
parentae30173d71d3bfc8514dbe70b6c90c9a3324b8fc (diff)
downloadtmwa-c080e504e4d74027b985b1ed675c172c083cea76.tar.gz
tmwa-c080e504e4d74027b985b1ed675c172c083cea76.tar.bz2
tmwa-c080e504e4d74027b985b1ed675c172c083cea76.tar.xz
tmwa-c080e504e4d74027b985b1ed675c172c083cea76.zip
Use cxxstdio
Diffstat (limited to 'src/common/lock.cpp')
-rw-r--r--src/common/lock.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
index 9075cbb..08ec2c4 100644
--- a/src/common/lock.cpp
+++ b/src/common/lock.cpp
@@ -4,6 +4,7 @@
#include <cstdio>
+#include "cxxstdio.hpp"
#include "socket.hpp"
/// Protected file writing
@@ -12,28 +13,28 @@
// Start writing a tmpfile
FILE *lock_fopen(const char *filename, int *info)
{
- char newfile[512];
FILE *fp;
int no = getpid();
// Get a filename that doesn't already exist
+ std::string newfile;
do
{
- sprintf(newfile, "%s_%d.tmp", filename, no++);
+ newfile = STRPRINTF("%s_%d.tmp", filename, no++);
+ fp = fopen_(newfile.c_str(), "wx");
}
- while ((fp = fopen_(newfile, "r")) && (fclose_(fp), 1));
+ while (!fp);
*info = --no;
- return fopen_(newfile, "w");
+ return fp;
}
// Delete the old file and rename the new file
-void lock_fclose(FILE * fp, const char *filename, int *info)
+void lock_fclose(FILE *fp, const char *filename, int *info)
{
- char newfile[512];
if (fp)
{
fclose_(fp);
- sprintf(newfile, "%s_%d.tmp", filename, *info);
- rename(newfile, filename);
+ std::string newfile = STRPRINTF("%s_%d.tmp", filename, *info);
+ rename(newfile.c_str(), filename);
}
}