summaryrefslogtreecommitdiffstats
path: root/mbbsd/passwd.c
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 04:11:24 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 04:11:24 +0800
commit95f0b420db24db279e1fb25b26973acf229e53e8 (patch)
tree72bd3843dbb180d2d78d998aa59431bffaf1b044 /mbbsd/passwd.c
parent1091228603cdb191d3c02e0f22468310140d0f32 (diff)
downloadpttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.gz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.bz2
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.lz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.xz
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.tar.zst
pttbbs-95f0b420db24db279e1fb25b26973acf229e53e8.zip
faster passwd by lower the lseek.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1627 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/passwd.c')
-rw-r--r--mbbsd/passwd.c84
1 files changed, 60 insertions, 24 deletions
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index 7686e566..67012f99 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -49,22 +49,37 @@ passwd_init()
}
int
-passwd_update_money(int num)
+passwd_update_money(int num) /* update money only */
{
- userec_t user;
- if (num < 1 || num > MAX_USERS)
+ userec_t user;
+ int pwdfd, money = moneyof(num);
+ char path[256];
+
+ if (num < 1 || num > MAX_USERS)
return -1;
- passwd_query(num, &user);
- if (SHM->loaded)
- user.money = moneyof(num);
- passwd_update(num, &user);
- return 0;
+
+ sethomefile(path, getuserid(num), ".passwd");
+
+ if ((pwdfd = open(path, O_WRONLY)) < 0)
+ {
+ if(passwd_index_query(num, &user)<0) // tempory code, will be removed
+ exit(1);
+ user.money=money;
+ passwd_update(num, &user);
+ return 0;
+ }
+
+ if(lseek(pwdfd, (off_t)((int)&user.money - (int)&user), SEEK_SET) >= 0)
+ write(pwdfd, &money, sizeof(int));
+
+ close(pwdfd);
+ return 0;
}
int
-passwd_update(int num, userec_t * buf)
+passwd_index_update(int num, userec_t * buf)
{
- int pwdfd;
+ int pwdfd;
if (num < 1 || num > MAX_USERS)
return -1;
buf->money = moneyof(num);
@@ -77,7 +92,22 @@ passwd_update(int num, userec_t * buf)
}
int
-passwd_query(int num, userec_t * buf)
+passwd_update(int num, userec_t * buf)
+{
+ int pwdfd;
+ char path[256];
+
+ sethomefile(path, getuserid(num), ".passwd");
+ buf->money = moneyof(num);
+ if ((pwdfd = open(path, O_RDWR)) < 0)
+ exit(1);
+ write(pwdfd, buf, sizeof(userec_t));
+ close(pwdfd);
+ return 0;
+}
+
+int
+passwd_index_query(int num, userec_t * buf)
{
int pwdfd;
if (num < 1 || num > MAX_USERS)
@@ -91,26 +121,32 @@ passwd_query(int num, userec_t * buf)
}
int
-passwd_apply(int (*fptr) (userec_t *))
+passwd_query(int num, userec_t * buf)
{
- int i;
- userec_t user;
- for (i = 0; i < MAX_USERS; i++) {
- passwd_query(i + 1, &user);
- if ((*fptr) (&user) == QUIT)
- return QUIT;
- }
- return 0;
+ int pwdfd;
+ char path[256];
+
+ sethomefile(path, getuserid(num), ".passwd");
+ if((pwdfd = open(path, O_RDONLY)) < 0)
+ { // copy from index // tempory code, will be removed
+ if(passwd_index_query(num, buf)<0)
+ exit(1);
+ passwd_update(num, buf);
+ return 0;
+ }
+ read(pwdfd, buf, sizeof(userec_t));
+ close(pwdfd);
+ return 0;
}
int
-passwd_apply2(int (*fptr)(int, userec_t *))
+passwd_apply(int (*fptr) (int, userec_t *))
{
- int i;
+ int i;
userec_t user;
- for(i = 0; i < MAX_USERS; i++){
+ for (i = 0; i < MAX_USERS; i++) {
passwd_query(i + 1, &user);
- if((*fptr)(i, &user) == QUIT)
+ if ((*fptr) (i, &user) == QUIT)
return QUIT;
}
return 0;