summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-11-15 20:30:49 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-11-15 21:43:08 -0800
commit672c4091b5a43442759886144607aa407a04e5bc (patch)
treecda5dc54039f6c711d07aae8890f99269c499a42 /src/common
parentf8747c4355f43b11489cc85eb8b5b922685fec39 (diff)
downloadtmwa-672c4091b5a43442759886144607aa407a04e5bc.tar.gz
tmwa-672c4091b5a43442759886144607aa407a04e5bc.tar.bz2
tmwa-672c4091b5a43442759886144607aa407a04e5bc.tar.xz
tmwa-672c4091b5a43442759886144607aa407a04e5bc.zip
Unbreak build
Diffstat (limited to 'src/common')
-rw-r--r--src/common/lock.cpp59
-rw-r--r--src/common/lock.hpp17
2 files changed, 0 insertions, 76 deletions
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
deleted file mode 100644
index e21aee5..0000000
--- a/src/common/lock.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "lock.hpp"
-
-#include <unistd.h>
-
-#include <cstdio>
-
-#include "../strings/fstring.hpp"
-#include "../strings/zstring.hpp"
-
-#include "cxxstdio.hpp"
-#include "socket.hpp"
-
-#include "../poison.hpp"
-
-/// number of backups to keep
-static
-const int backup_count = 10;
-
-/// Protected file writing
-/// (Until the file is closed, it keeps the old file)
-
-// Start writing a tmpfile
-FILE *lock_fopen(ZString filename, int *info)
-{
- FILE *fp;
- int no = getpid();
-
- // Get a filename that doesn't already exist
- FString newfile;
- do
- {
- newfile = STRPRINTF("%s_%d.tmp", filename, no++);
- fp = fopen(newfile.c_str(), "wx");
- }
- while (!fp);
- *info = --no;
- return fp;
-}
-
-// Delete the old file and rename the new file
-void lock_fclose(FILE *fp, ZString filename, int *info)
-{
- if (fp)
- {
- fclose(fp);
- int n = backup_count;
- FString old_filename = STRPRINTF("%s.%d", filename, n);
- while (--n)
- {
- FString newer_filename = STRPRINTF("%s.%d", filename, n);
- rename(newer_filename.c_str(), old_filename.c_str());
- old_filename = std::move(newer_filename);
- }
- rename(filename.c_str(), old_filename.c_str());
-
- FString tmpfile = STRPRINTF("%s_%d.tmp", filename, *info);
- rename(tmpfile.c_str(), filename.c_str());
- }
-}
diff --git a/src/common/lock.hpp b/src/common/lock.hpp
deleted file mode 100644
index 5ca1aed..0000000
--- a/src/common/lock.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef LOCK_HPP
-#define LOCK_HPP
-
-#include "sanity.hpp"
-
-#include <cstdio>
-
-#include "../strings/fwd.hpp"
-
-// TODO replace with a class
-
-/// Locked FILE I/O
-// Changes are made in a separate file until lock_fclose
-FILE *lock_fopen(ZString filename, int *info);
-void lock_fclose(FILE *fp, ZString filename, int *info);
-
-#endif // LOCK_HPP