From 093e88b99f01594ca10618c6bfa03acddf6dcfa4 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 25 Aug 2002 07:13:53 +0000 Subject: edit lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@493 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/edit.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'mbbsd/edit.c') diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 589be70d..db335241 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.16 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: edit.c,v 1.17 2002/08/25 07:13:53 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -2280,3 +2280,40 @@ vedit(char *fpath, int saveheader, int *islocal) } } } + +void editlock(char *fpath) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "w")) != NULL ){ + fprintf(fp, "%d\n", currpid); + fclose(fp); + } +} + +void editunlock(char *fpath) +{ + char fn[256]; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + unlink(fn); +} + +int iseditlocking(char *fpath, char *action) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "r")) != NULL ){ + int pid; + fscanf(fp, "%d", &pid); + fclose(fp); + if( kill(pid, 0) >= 0 ){ + vmsg("文章編修中, 暫時無法%s", action); + return 1; + } + else + unlink(fn); + } + return 0; +} -- cgit v1.2.3