From 672c4091b5a43442759886144607aa407a04e5bc Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 15 Nov 2013 20:30:49 -0800 Subject: Unbreak build --- src/common/lock.cpp | 59 ----------------------------------------------------- src/common/lock.hpp | 17 --------------- 2 files changed, 76 deletions(-) delete mode 100644 src/common/lock.cpp delete mode 100644 src/common/lock.hpp (limited to 'src/common') 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 - -#include - -#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 - -#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 -- cgit v1.2.3-60-g2f50