diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-08-31 13:22:39 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-08-31 13:22:39 -0600 |
commit | 67a8847e17aa72981bbf3b4c15167cc0ef499da1 (patch) | |
tree | 30b07708a5893712ea1a0bb4835881caa3dd97f7 /src/common/lock.c | |
parent | 0e36f6e8d82e7cb0f01683454790a7123ea03197 (diff) | |
parent | dbd9d0321c66deeecf01445f8298aa5076391fbd (diff) | |
download | tmwa-67a8847e17aa72981bbf3b4c15167cc0ef499da1.tar.gz tmwa-67a8847e17aa72981bbf3b4c15167cc0ef499da1.tar.bz2 tmwa-67a8847e17aa72981bbf3b4c15167cc0ef499da1.tar.xz tmwa-67a8847e17aa72981bbf3b4c15167cc0ef499da1.zip |
Merge commit 'taw/master'
Diffstat (limited to 'src/common/lock.c')
-rw-r--r-- | src/common/lock.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/common/lock.c b/src/common/lock.c index 67001f9..42bbff0 100644 --- a/src/common/lock.c +++ b/src/common/lock.c @@ -1,4 +1,5 @@ +#include <unistd.h> #include <stdio.h> #include "lock.h" #include "socket.h" @@ -10,13 +11,13 @@ FILE* lock_fopen(const char* filename,int *info) { char newfile[512]; FILE *fp; - int no = 0; + int no = getpid(); // 安全なファイル名を得る(手抜き) do { - sprintf(newfile,"%s_%04d.tmp",filename,++no); - } while((fp = fopen_(newfile,"r")) && (fclose_(fp), no<9999) ); - *info = no; + sprintf(newfile,"%s_%d.tmp",filename,no++); + } while((fp = fopen_(newfile,"r")) && fclose_(fp)); + *info = --no; return fopen_(newfile,"w"); } @@ -26,7 +27,7 @@ int lock_fclose(FILE *fp,const char* filename,int *info) { char newfile[512]; if(fp != NULL) { ret = fclose_(fp); - sprintf(newfile,"%s_%04d.tmp",filename,*info); + sprintf(newfile,"%s_%d.tmp",filename,*info); remove(filename); // このタイミングで落ちると最悪。 rename(newfile,filename); |