summaryrefslogtreecommitdiff
path: root/src/common/lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/lock.c')
-rw-r--r--src/common/lock.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/common/lock.c b/src/common/lock.c
index e4ec36302..5cb4c3a67 100644
--- a/src/common/lock.c
+++ b/src/common/lock.c
@@ -11,21 +11,12 @@
#ifndef WIN32
#include <unistd.h>
#else
-#include <windows.h>
+#include <io.h>
#define F_OK 0x0
#define R_OK 0x4
#endif
-#ifndef WIN32
- #define exists(filename) (!access(filename, F_OK))
-#else
-// could be speed up maybe?
-int exists(char *file) {
- FILE *fp;
- if ((fp = fopen(file,"r")) && fclose(fp) == 0) return 1;
- return 0;
-}
-#endif
+#define exists(filename) (!access(filename, F_OK))
// 書き込みファイルの保護処理
// (書き込みが終わるまで、旧ファイルを保管しておく)
@@ -33,13 +24,12 @@ int exists(char *file) {
// 新しいファイルの書き込み開始
FILE* lock_fopen (const char* filename, int *info) {
char newfile[512];
- FILE *fp;
int no = 0;
// 安全なファイル名を得る(手抜き)
do {
sprintf(newfile, "%s_%04d.tmp", filename, ++no);
- } while((fp = fopen(newfile,"r")) && (fclose(fp), no < 9999));
+ } while(exists(newfile) && no < 9999);
*info = no;
return fopen(newfile,"w");
}