summaryrefslogtreecommitdiffstats
path: root/mbbsd/passwd.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
commit1603deaec5d0a94c9a8201b0ba286e8e492a3602 (patch)
treee6405cfd39f8ac166ab7d00752ed6cfa3ac0a928 /mbbsd/passwd.c
parent10bda3e57cad194ac33ccdcd01aee2d935f1544a (diff)
downloadpttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.gz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.bz2
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.lz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.xz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.zst
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.zip
indent
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@415 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/passwd.c')
-rw-r--r--mbbsd/passwd.c94
1 files changed, 54 insertions, 40 deletions
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index 06a26d32..9c129dc0 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -1,7 +1,7 @@
-/* $Id: passwd.c,v 1.6 2002/07/04 19:46:16 in2 Exp $ */
+/* $Id: passwd.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */
#include "bbs.h"
-static int semid = -1;
+static int semid = -1;
#ifndef SEM_R
#define SEM_R 0400
@@ -13,19 +13,21 @@ static int semid = -1;
#ifndef __FreeBSD__
union semun {
- int val; /* value for SETVAL */
- struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
- u_short *array; /* array for GETALL & SETALL */
- struct seminfo *__buf; /* buffer for IPC_INFO */
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ u_short *array; /* array for GETALL & SETALL */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
};
#endif
-int passwd_init() {
+int
+passwd_init()
+{
semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL);
- if(semid == -1) {
- if(errno == EEXIST) {
+ if (semid == -1) {
+ if (errno == EEXIST) {
semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A);
- if(semid == -1) {
+ if (semid == -1) {
perror("semget");
exit(1);
}
@@ -34,10 +36,10 @@ int passwd_init() {
exit(1);
}
} else {
- union semun s;
-
+ union semun s;
+
s.val = 1;
- if(semctl(semid, 0, SETVAL, s) == -1) {
+ if (semctl(semid, 0, SETVAL, s) == -1) {
perror("semctl");
exit(1);
}
@@ -46,23 +48,27 @@ int passwd_init() {
return 0;
}
-int passwd_update_money(int num) {
- userec_t user;
- if(num < 1 || num > MAX_USERS)
- return -1;
+int
+passwd_update_money(int num)
+{
+ userec_t user;
+ if (num < 1 || num > MAX_USERS)
+ return -1;
passwd_query(num, &user);
- if( SHM->loaded )
+ if (SHM->loaded)
user.money = moneyof(num);
passwd_update(num, &user);
return 0;
-}
+}
-int passwd_update(int num, userec_t *buf) {
- int pwdfd;
- if(num < 1 || num > MAX_USERS)
+int
+passwd_update(int num, userec_t * buf)
+{
+ int pwdfd;
+ if (num < 1 || num > MAX_USERS)
return -1;
buf->money = moneyof(num);
- if( (pwdfd = open(fn_passwd, O_RDWR)) < 0 )
+ if ((pwdfd = open(fn_passwd, O_RDWR)) < 0)
exit(1);
lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET);
write(pwdfd, buf, sizeof(userec_t));
@@ -70,11 +76,13 @@ int passwd_update(int num, userec_t *buf) {
return 0;
}
-int passwd_query(int num, userec_t *buf) {
- int pwdfd;
- if(num < 1 || num > MAX_USERS)
+int
+passwd_query(int num, userec_t * buf)
+{
+ int pwdfd;
+ if (num < 1 || num > MAX_USERS)
return -1;
- if( (pwdfd = open(fn_passwd, O_RDONLY)) < 0 )
+ if ((pwdfd = open(fn_passwd, O_RDONLY)) < 0)
exit(1);
lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET);
read(pwdfd, buf, sizeof(userec_t));
@@ -82,30 +90,36 @@ int passwd_query(int num, userec_t *buf) {
return 0;
}
-int passwd_apply(int (*fptr)(userec_t *)) {
- int i;
- userec_t user;
- for(i = 0; i < MAX_USERS; i++){
+int
+passwd_apply(int (*fptr) (userec_t *))
+{
+ int i;
+ userec_t user;
+ for (i = 0; i < MAX_USERS; i++) {
passwd_query(i + 1, &user);
- if((*fptr)(&user) == QUIT)
+ if ((*fptr) (&user) == QUIT)
return QUIT;
}
return 0;
}
-void passwd_lock() {
- struct sembuf buf = { 0, -1, SEM_UNDO };
-
- if(semop(semid, &buf, 1)) {
+void
+passwd_lock()
+{
+ struct sembuf buf = {0, -1, SEM_UNDO};
+
+ if (semop(semid, &buf, 1)) {
perror("semop");
exit(1);
}
}
-void passwd_unlock() {
- struct sembuf buf = { 0, 1, SEM_UNDO };
-
- if(semop(semid, &buf, 1)) {
+void
+passwd_unlock()
+{
+ struct sembuf buf = {0, 1, SEM_UNDO};
+
+ if (semop(semid, &buf, 1)) {
perror("semop");
exit(1);
}