diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-11-07 00:25:15 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-11-07 00:25:15 +0800 |
commit | 3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a (patch) | |
tree | 772cecc4731614e9df09367ab0d5f0f8654be4b4 /mbbsd/record.c | |
parent | 175ba7e7cf70d131d34fd8c09a3138e7f9dfeea0 (diff) | |
download | pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar.gz pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar.bz2 pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar.lz pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar.xz pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.tar.zst pttbbs-3135cf3e37a4b5fbd7b7b4e7a67b66c47d0e1e3a.zip |
editlock by flock()
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@558 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/record.c')
-rw-r--r-- | mbbsd/record.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c index bd0c5316..13db0da6 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.10 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: record.c,v 1.11 2002/11/06 16:25:15 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -91,6 +91,38 @@ get_records(char *fpath, void *rptr, int size, int id, int number) } int +lock_substitute_record(char *fpath, void *rptr, int size, int id, int mode) +{ + static int fd = -1; + switch( mode ){ + case LOCK_EX: + if( id < 1 || (fd = open(fpath, O_RDWR | O_CREAT, 0644)) == -1 ) + return -1; + + if( flock(fd, LOCK_EX) < 0 ){ + close(fd); + return -1; + } + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + read(fd, rptr, size); + return 0; + + case LOCK_UN: + if( fd < 0 ) + return -1; + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + write(fd, rptr, size); + flock(fd, LOCK_UN); + close(fd); + fd = -1; + return 0; + + default: + return -1; + } +} + +int substitute_record(char *fpath, void *rptr, int size, int id) { int fd; |