summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/bbs.h45
-rw-r--r--include/osdep.h51
-rw-r--r--include/proto.h34
-rw-r--r--mbbsd/admin.c4
-rw-r--r--mbbsd/bbs.c4
-rw-r--r--mbbsd/cache.c2
-rw-r--r--mbbsd/chat.c2
-rw-r--r--mbbsd/chc.c6
-rw-r--r--mbbsd/edit.c20
-rw-r--r--mbbsd/io.c2
-rw-r--r--mbbsd/mail.c6
-rw-r--r--mbbsd/mbbsd.c9
-rw-r--r--mbbsd/name.c2
-rw-r--r--mbbsd/osdep.c447
-rw-r--r--mbbsd/talk.c8
-rw-r--r--mbbsd/topsong.c2
-rw-r--r--mbbsd/user.c8
-rw-r--r--pttbbs.mk13
18 files changed, 421 insertions, 244 deletions
diff --git a/include/bbs.h b/include/bbs.h
index 81ed235e..5b4dca21 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -34,50 +34,7 @@
#include <sys/sem.h>
#include <sys/msg.h>
-/* os dependant include file, define */
-#ifdef __FreeBSD__
- #if __FreeBSD__ >=5
- #include <sys/limits.h>
- #else
- #include <machine/limits.h>
- #endif
- #include <machine/param.h>
-
-#elif defined(__linux__)
- #include <sys/param.h>
- #include <sys/ioctl.h>
- #include <limits.h>
- #include <sys/file.h> /* for flock() */
- #include <strings.h> /* for strcasecmp() */
- size_t
- strlcpy(char *dst, const char *src, size_t size);
-
- size_t
- strlcat(char *dst, const char *src, size_t size);
-
-#elif defined(Solaris)
-
-#include <alloca.h>
-#include <crypt.h>
-#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <limits.h>
-#include <strings.h> /* for strcasecmp() */
-
-#define LOCK_EX 1
-#define LOCK_UN 2
-
-int flock(int, int);
-
-void unsetenv(char *name);
-
-int scandir(const char *dirname, struct dirent ***namelist, int (*select)(struct dirent *), int (*compar)(const void *, const void *));
-int alphasort(const void *d1, const void *d2);
-
-
-#else
-#warning "Unknown OSTYPE"
-#endif
+#include "osdep.h"
/* our header */
#include "config.h"
diff --git a/include/osdep.h b/include/osdep.h
new file mode 100644
index 00000000..c9223ba3
--- /dev/null
+++ b/include/osdep.h
@@ -0,0 +1,51 @@
+
+#ifndef __OSDEP_H__
+#define __OSDEP_H__
+
+/* os dependant include file, define */
+#ifdef __FreeBSD__
+ #if __FreeBSD__ >=5
+ #include <sys/limits.h>
+ #else
+ #include <machine/limits.h>
+ #endif
+ #include <machine/param.h>
+
+#elif defined(__linux__)
+
+ #include <sys/param.h>
+ #include <sys/ioctl.h>
+ #include <limits.h>
+ #include <sys/file.h> /* for flock() */
+ #include <strings.h> /* for strcasecmp() */
+
+ #define NEED_STRCASESTR
+ #define NEED_STRLCPY
+ #define NEED_STRLCAT
+
+#elif defined(Solaris)
+
+ #include <alloca.h>
+ #include <crypt.h>
+ #include <sys/param.h>
+ #include <sys/ioctl.h>
+ #include <limits.h>
+ #include <strings.h> /* for strcasecmp() */
+
+ #define NEED_FLOCK
+ #define NEED_UNSETENV
+ #define NEED_SCANDIR
+ #define NEED_STRCASESTR
+
+ #if __OS_MAJOR_VERSION__ == 5 && __OS_MINOR_VERSION__ < 8
+ #define NEED_STRLCPY
+ #define NEED_STRLCAT
+ #define NEED_INET_PTON
+ #endif
+
+#else
+ #warning "Unknown OSTYPE"
+#endif
+
+
+#endif
diff --git a/include/proto.h b/include/proto.h
index ab56650a..41237c3e 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -374,11 +374,41 @@ int completeutmp_compar(int where, char *str, int len);
int completeutmp_permission(int where);
char *completeutmp_getname(int where);
+
/* osdep */
int cpuload(char *str);
double swapused(int *total, int *used);
-#if defined(__linux__) || defined(Solaris)
-char *strcasestr(const char *big, const char *little);
+
+#ifdef NEED_FLOCK
+ #define LOCK_EX 1
+ #define LOCK_UN 2
+
+ int flock(int, int);
+#endif
+
+#ifdef NEED_UNSETENV
+ void unsetenv(char *name);
+#endif
+
+#ifdef NEED_STRCASESTR
+ char *strcasestr(const char *big, const char *little);
+#endif
+
+#ifdef NEED_STRLCPY
+ size_t strlcpy(char *dst, const char *src, size_t size);
+#endif
+
+#ifdef NEED_STRLCAT
+ size_t strlcat(char *dst, const char *src, size_t size);
+#endif
+
+#ifdef NEED_SCANDIR
+ int scandir(const char *dirname, struct dirent ***namelist, int (*select)(struct dirent *), int (*compar)(const void *, const void *));
+ int alphasort(const void *d1, const void *d2);
+#endif
+
+#ifdef NEED_INET_PTON
+ int inet_pton(int af, const char *src, void *dst);
#endif
/* othello */
diff --git a/mbbsd/admin.c b/mbbsd/admin.c
index f115bf46..de40efe1 100644
--- a/mbbsd/admin.c
+++ b/mbbsd/admin.c
@@ -1012,7 +1012,7 @@ auto_scan(char fdata[][STRLEN], char ans[])
}
}
for (i = 0; fdata[5][i]; i++) {
- if (isdigit(fdata[5][i]))
+ if (isdigit((int)fdata[5][i]))
count++;
}
@@ -1196,7 +1196,7 @@ scan_register_form(char *regfile, int automode, int neednum)
fp = fopen(buf1, "w");
for(i = 0; buf[i] && i < sizeof(buf); i++){
- if (!isdigit(buf[i]))
+ if (!isdigit((int)buf[i]))
continue;
fprintf(fp, "[退回原因] 請%s\n",
reason[buf[i] - '0']);
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 26080e1d..94a4b7f7 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -798,7 +798,7 @@ invalid_brdname(char *brd)
register char ch, rv=0;
ch = *brd++;
- if (!isalpha(ch))
+ if (!isalpha((int)ch))
rv = 2;
while ((ch = *brd++)) {
if (not_alnum(ch) && ch != '_' && ch != '-' && ch != '.')
@@ -1802,7 +1802,7 @@ view_postmoney(int ent, fileheader_t * fhdr, char *direct)
/* When the file is anonymous posted, fhdr->money is author.
* see do_general() */
vmsg("匿名管理編號: %d (同一人號碼會一樣)",
- fhdr->money + currutmp->pid);
+ fhdr->money + (int)currutmp->pid);
else
vmsg("這一篇文章值 %d 銀", fhdr->money);
return FULLUPDATE;
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 4756b359..d826199f 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -741,7 +741,7 @@ void buildBMcache(int bid) /* bid starts from 1 */
strncpy(s, bcache[bid].BM, sizeof(s));
for( i = 0 ; s[i] != 0 ; ++i )
- if( !isalpha(s[i]) && !isdigit(s[i]) )
+ if( !isalpha((int)s[i]) && !isdigit((int)s[i]) )
s[i] = ' ';
for( ptr = strtok(s, " "), i = 0 ;
diff --git a/mbbsd/chat.c b/mbbsd/chat.c
index b911b47c..caf3f1b8 100644
--- a/mbbsd/chat.c
+++ b/mbbsd/chat.c
@@ -268,7 +268,7 @@ const static chat_command_t chat_cmdtbl[] = {
static int
chat_cmd_match(char *buf, char *str)
{
- while (*str && *buf && !isspace(*buf))
+ while (*str && *buf && !isspace((int)*buf))
if (tolower(*buf++) != *str++)
return 0;
return 1;
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index 1db17c95..54a351ba 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -306,7 +306,7 @@ chc_log_step(board_t board, rc_t *from, rc_t *to)
}
static int
-#if defined(__linux__) || defined(Solaris)
+#if defined(__linux__)
chc_filter(const struct dirent *dir)
#else
chc_filter(struct dirent *dir)
@@ -1030,7 +1030,11 @@ chc_watch(void)
vmsg("無法建立連線");
return -1;
}
+#if defined(Solaris) && __OS_MAJOR_VERSION__ == 5 && __OS_MINOR_VERSION__ < 7
+ msgsock = accept(sock, (struct sockaddr *) 0, 0);
+#else
msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0);
+#endif
close(sock);
if (msgsock < 0)
return -1;
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index aa08e7c7..088c7717 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -132,7 +132,7 @@ ansi2n(int ansix, textline_t * line)
while (*tmp) {
if (*tmp == KEY_ESC) {
- while ((ch = *tmp) && !isalpha(ch))
+ while ((ch = *tmp) && !isalpha((int)ch))
tmp++;
if (ch)
tmp++;
@@ -158,7 +158,7 @@ n2ansi(int nx, textline_t * line)
while (*tmp) {
if (*tmp == KEY_ESC) {
- while ((ch = *tmp) && !isalpha(ch))
+ while ((ch = *tmp) && !isalpha((int)ch))
tmp++;
if (ch)
tmp++;
@@ -992,7 +992,7 @@ addsignature(FILE * fp, int ifuseanony)
if (!buf[0])
buf[0] = ch;
- if (isdigit(buf[0]))
+ if (isdigit((int)buf[0]))
ch = buf[0];
else
ch = '1' + rand() % num;
@@ -2012,7 +2012,7 @@ vedit(char *fpath, int saveheader, int *islocal)
int fg, bg;
strcpy(color, "\033[");
- if (isdigit(*apos)) {
+ if (isdigit((int)*apos)) {
sprintf(color,"%s%c", color, *(apos++));
if (*apos)
strcat(color, ";");
@@ -2133,25 +2133,25 @@ vedit(char *fpath, int saveheader, int *islocal)
break;
case 'f':
while (currpnt < currline->len &&
- isalnum(currline->data[++currpnt]));
+ isalnum((int)currline->data[++currpnt]));
while (currpnt < currline->len &&
- isspace(currline->data[++currpnt]));
+ isspace((int)currline->data[++currpnt]));
line_dirty = 1;
break;
case 'b':
- while (currpnt && isalnum(currline->data[--currpnt]));
- while (currpnt && isspace(currline->data[--currpnt]));
+ while (currpnt && isalnum((int)currline->data[--currpnt]));
+ while (currpnt && isspace((int)currline->data[--currpnt]));
line_dirty = 1;
break;
case 'd':
while (currpnt < currline->len) {
delete_char();
- if (!isalnum(currline->data[currpnt]))
+ if (!isalnum((int)currline->data[currpnt]))
break;
}
while (currpnt < currline->len) {
delete_char();
- if (!isspace(currline->data[currpnt]))
+ if (!isspace((int)currline->data[currpnt]))
break;
}
line_dirty = 1;
diff --git a/mbbsd/io.c b/mbbsd/io.c
index 75d38c96..48ea042f 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -636,7 +636,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo)
outc('\n');
refresh();
}
- if ((echo == LCECHO) && isupper(buf[0]))
+ if ((echo == LCECHO) && isupper((int)buf[0]))
buf[0] = tolower(buf[0]);
return clen;
}
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 767bf5e2..94f936cd 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -1587,15 +1587,15 @@ doforward(char *direct, fileheader_t * fh, int mode)
} else if (mode == 'U') {
char tmp_buf[128];
- snprintf(fname, sizeof(fname), "/tmp/bbs.uu%05d", currpid);
+ snprintf(fname, sizeof(fname), "/tmp/bbs.uu%05d", (int)currpid);
snprintf(tmp_buf, sizeof(tmp_buf),
"/usr/bin/uuencode %s/%s uu.%05d > %s",
- direct, fh->filename, currpid, fname);
+ direct, fh->filename, (int)currpid, fname);
system(tmp_buf);
} else if (mode == 'F') {
char tmp_buf[128];
- snprintf(fname, sizeof(fname), "/tmp/bbs.f%05d", currpid);
+ snprintf(fname, sizeof(fname), "/tmp/bbs.f%05d", (int)currpid);
snprintf(tmp_buf, sizeof(tmp_buf),
"cp %s/%s %s", direct, fh->filename, fname);
system(tmp_buf);
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index eb935696..4b343466 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -1362,17 +1362,22 @@ daemon_login(int argc, char *argv[], char *envp[])
#endif
#endif
- snprintf(buf, sizeof(buf), "run/mbbsd.%d.%d.pid", listen_port, getpid());
+ snprintf(buf, sizeof(buf), "run/mbbsd.%d.%d.pid", listen_port, (int)getpid());
if ((fp = fopen(buf, "w"))) {
- fprintf(fp, "%d\n", getpid());
+ fprintf(fp, "%d\n", (int)getpid());
fclose(fp);
}
/* main loop */
while( 1 ){
len_of_sock_addr = sizeof(xsin);
+#if defined(Solaris) && __OS_MAJOR_VERSION__ == 5 && __OS_MINOR_VERSION__ < 7
+ if( (csock = accept(msock, (struct sockaddr *)&xsin,
+ &len_of_sock_addr)) < 0 ){
+#else
if( (csock = accept(msock, (struct sockaddr *)&xsin,
(socklen_t *)&len_of_sock_addr)) < 0 ){
+#endif
if (errno != EINTR)
sleep(1);
continue;
diff --git a/mbbsd/name.c b/mbbsd/name.c
index 6ee8849f..db96eb08 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -449,7 +449,7 @@ usercomplete(char *prompt, char *data)
outc(' ');
move(y, x);
continue;
- } else if (count < STRLEN && isprint(ch)) {
+ } else if (count < STRLEN && isprint((int)ch)) {
int n;
*temp++ = ch;
diff --git a/mbbsd/osdep.c b/mbbsd/osdep.c
index 8354b693..ac5dd97b 100644
--- a/mbbsd/osdep.c
+++ b/mbbsd/osdep.c
@@ -1,7 +1,8 @@
/* $Id$ */
#include "bbs.h"
-#if defined(__linux__)
+#ifdef NEED_STRLCAT
+
#include <sys/types.h>
#include <string.h>
@@ -44,35 +45,39 @@
*/
size_t
strlcat(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
+ char *dst;
+ const char *src;
+ size_t siz;
{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
- size_t dlen;
-
- /* Find the end of dst and adjust bytes left but don't go past end */
- while (n-- != 0 && *d != '\0')
- d++;
- dlen = d - dst;
- n = siz - dlen;
-
- if (n == 0)
- return(dlen + strlen(s));
- while (*s != '\0') {
- if (n != 1) {
- *d++ = *s;
- n--;
- }
- s++;
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
}
- *d = '\0';
+ s++;
+ }
+ *d = '\0';
- return(dlen + (s - src)); /* count does not include NUL */
+ return(dlen + (s - src)); /* count does not include NUL */
}
+#endif
+
+#ifdef NEED_STRLCPY
+
/* ------------------------------------------------------------------------ */
/* size_t
@@ -112,36 +117,37 @@ strlcat(dst, src, siz)
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t strlcpy(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
+ char *dst;
+ const char *src;
+ size_t siz;
{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0) {
- do {
- if ((*d++ = *s++) == 0)
- break;
- } while (--n != 0);
- }
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
- return(s - src - 1); /* count does not include NUL */
+ return(s - src - 1); /* count does not include NUL */
}
#endif
-#if defined(linux) || defined(Solaris)
+#ifdef NEED_STRCASESTR
+
char *
strcasestr(const char *big, const char *little)
{
@@ -159,17 +165,13 @@ strcasestr(const char *big, const char *little)
#endif
-#ifdef Solaris
+#ifdef NEED_SCANDIR
/*
- * Scan the directory dirname calling select to make a list of
-selected
- * directory entries then sort using qsort and compare routine
-dcomp.
- * Returns the number of entries and a pointer to a list of
-pointers to
- * struct dirent (through namelist). Returns -1 if there were any
-errors.
+ * Scan the directory dirname calling select to make a list of selected
+ * directory entries then sort using qsort and compare routine dcomp.
+ * Returns the number of entries and a pointer to a list of pointers to
+ * struct dirent (through namelist). Returns -1 if there were any errors.
*/
#include <sys/types.h>
@@ -179,91 +181,88 @@ errors.
#include <string.h>
/*
- * The DIRSIZ macro is the minimum record length which will hold
-the directory
- * entry. This requires the amount of space in struct dirent
-without the
- * d_name field, plus enough space for the name and a terminating
-nul byte
+ * The DIRSIZ macro is the minimum record length which will hold the directory
+ * entry. This requires the amount of space in struct dirent without the
+ * d_name field, plus enough space for the name and a terminating nul byte
* (dp->d_namlen + 1), rounded up to a 4 byte boundary.
*/
#undef DIRSIZ
#define DIRSIZ(dp) \
- ((sizeof(struct dirent) - sizeof(dp)->d_name) + \
- ((strlen((dp)->d_name) + 1 + 3) &~ 3))
+ ((sizeof(struct dirent) - sizeof(dp)->d_name) + \
+ ((strlen((dp)->d_name) + 1 + 3) &~ 3))
#if 0
- ((sizeof(struct dirent) - sizeof(dp)->d_name) + \
- (((dp)->d_namlen + 1 + 3) &~ 3))
+((sizeof(struct dirent) - sizeof(dp)->d_name) + \
+ (((dp)->d_namlen + 1 + 3) &~ 3))
#endif
int
scandir(dirname, namelist, select, dcomp)
- const char *dirname;
- struct dirent ***namelist;
- int (*select) (struct dirent *);
- int (*dcomp) (const void *, const void *);
+ const char *dirname;
+ struct dirent ***namelist;
+ int (*select) (struct dirent *);
+ int (*dcomp) (const void *, const void *);
{
- register struct dirent *d, *p, **names;
- register size_t nitems;
- struct stat stb;
- long arraysz;
- DIR *dirp;
-
- if ((dirp = opendir(dirname)) == NULL)
- return(-1);
- if (fstat(dirp->dd_fd, &stb) < 0)
- return(-1);
-
- /*
- * estimate the array size by taking the size of thedirectory file
- * and dividing it by a multiple of the minimum sizeentry.
- */
- arraysz = (stb.st_size / 24);
- names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
- if (names == NULL)
- return(-1);
-
- nitems = 0;
- while ((d = readdir(dirp)) != NULL) {
- if (select != NULL && !(*select)(d))
- continue; /* just selected names */
- /*
- * Make a minimum size copy of the data
- */
- p = (struct dirent *)malloc(DIRSIZ(d));
- if (p == NULL)
- return(-1);
- p->d_ino = d->d_ino;
- p->d_off = d->d_off;
- p->d_reclen = d->d_reclen;
- memcpy(p->d_name, d->d_name, strlen(d->d_name) +1);
+ register struct dirent *d, *p, **names;
+ register size_t nitems;
+ struct stat stb;
+ long arraysz;
+ DIR *dirp;
+
+ if ((dirp = opendir(dirname)) == NULL)
+ return(-1);
+ if (fstat(dirp->dd_fd, &stb) < 0)
+ return(-1);
+
+ /*
+ * estimate the array size by taking the size of thedirectory file
+ * and dividing it by a multiple of the minimum sizeentry.
+ */
+ arraysz = (stb.st_size / 24);
+ names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
+ if (names == NULL)
+ return(-1);
+
+ nitems = 0;
+ while ((d = readdir(dirp)) != NULL) {
+ if (select != NULL && !(*select)(d))
+ continue; /* just selected names */
+ /*
+ * Make a minimum size copy of the data
+ */
+ p = (struct dirent *)malloc(DIRSIZ(d));
+ if (p == NULL)
+ return(-1);
+ p->d_ino = d->d_ino;
+ p->d_off = d->d_off;
+ p->d_reclen = d->d_reclen;
+ memcpy(p->d_name, d->d_name, strlen(d->d_name) +1);
#if 0
- p->d_fileno = d->d_fileno;
- p->d_type = d->d_type;
- p->d_reclen = d->d_reclen;
- p->d_namlen = d->d_namlen;
- bcopy(d->d_name, p->d_name, p->d_namlen + 1);
+ p->d_fileno = d->d_fileno;
+ p->d_type = d->d_type;
+ p->d_reclen = d->d_reclen;
+ p->d_namlen = d->d_namlen;
+ bcopy(d->d_name, p->d_name, p->d_namlen + 1);
#endif
- /*
- * Check to make sure the array has space left and
- * realloc the maximum size.
- */
- if (++nitems >= arraysz) {
- if (fstat(dirp->dd_fd, &stb) < 0)
- return(-1); /* just might have grown */
- arraysz = stb.st_size / 12;
- names = (struct dirent **)realloc((char*)names,
- arraysz * sizeof(struct dirent*));
- if (names == NULL)
- return(-1);
- }
- names[nitems-1] = p;
- }
- closedir(dirp);
- if (nitems && dcomp != NULL)
- qsort(names, nitems, sizeof(struct dirent *),dcomp);
- *namelist = names;
- return(nitems);
+ /*
+ * Check to make sure the array has space left and
+ * realloc the maximum size.
+ */
+ if (++nitems >= arraysz) {
+ if (fstat(dirp->dd_fd, &stb) < 0)
+ return(-1); /* just might have grown */
+ arraysz = stb.st_size / 12;
+ names = (struct dirent **)realloc((char*)names,
+ arraysz * sizeof(struct dirent*));
+ if (names == NULL)
+ return(-1);
+ }
+ names[nitems-1] = p;
+ }
+ closedir(dirp);
+ if (nitems && dcomp != NULL)
+ qsort(names, nitems, sizeof(struct dirent *),dcomp);
+ *namelist = names;
+ return(nitems);
}
/*
@@ -271,50 +270,104 @@ scandir(dirname, namelist, select, dcomp)
*/
int
alphasort(d1, d2)
- const void *d1;
- const void *d2;
+ const void *d1;
+ const void *d2;
{
- return(strcmp((*(struct dirent **)d1)->d_name,
- (*(struct dirent **)d2)->d_name));
+ return(strcmp((*(struct dirent **)d1)->d_name,
+ (*(struct dirent **)d2)->d_name));
}
+
+#endif
+
+#ifdef NEED_FLOCK
+
int
flock (int fd, int f)
{
if( f == LOCK_EX )
- return lockf(fd, F_LOCK, 0L);
+ return lockf(fd, F_LOCK, 0L);
if( f == LOCK_UN )
- return lockf(fd, F_ULOCK, 0L);
+ return lockf(fd, F_ULOCK, 0L);
return -1;
}
+#endif
+
+#ifdef NEED_UNSETENV
+
void
unsetenv(name)
- char *name;
+ char *name;
{
- extern char **environ;
- register char **pp;
- int len = strlen(name);
-
- for (pp = environ; *pp != NULL; pp++)
- {
- if (strncmp(name, *pp, len) == 0 &&
- ((*pp)[len] == '=' || (*pp)[len] == '\0'))
- break;
- }
-
- for (; *pp != NULL; pp++)
- *pp = pp[1];
+ extern char **environ;
+ register char **pp;
+ int len = strlen(name);
+
+ for (pp = environ; *pp != NULL; pp++)
+ {
+ if (strncmp(name, *pp, len) == 0 &&
+ ((*pp)[len] == '=' || (*pp)[len] == '\0'))
+ break;
+ }
+
+ for (; *pp != NULL; pp++)
+ *pp = pp[1];
}
+#endif
+
+#ifdef NEED_INET_PTON
+
+#include <arpa/nameser.h>
+
+int
+inet_pton(int af, const char *src, void *dst)
+{
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ u_char tmp[INADDRSZ], *tp;
+
+ saw_digit = 0;
+ octets = 0;
+ *(tp = tmp) = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
+
+ if ((pch = strchr(digits, ch)) != NULL) {
+ u_int new = *tp * 10 + (pch - digits);
+
+ if (new > 255)
+ return (0);
+ *tp = new;
+ if (! saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+ memcpy(dst, tmp, INADDRSZ);
+ return (1);
+}
+#endif
+#ifdef Solaris
+
#include <sys/stat.h>
#include <sys/swap.h>
-#include <sys/loadavg.h>
double swapused(int *total, int *used)
@@ -327,10 +380,10 @@ double swapused(int *total, int *used)
static char path[256];
cnt = swapctl(SC_GETNSWP, 0);
swt = (struct swaptable *)malloc(sizeof(int) +
- cnt * sizeof(struct swapent));
+ cnt * sizeof(struct swapent));
if (swt == NULL)
{
- return 0;
+ return 0;
}
swt->swt_n = cnt;
@@ -340,7 +393,7 @@ double swapused(int *total, int *used)
i = cnt;
while (--i >= 0)
{
- ste++->ste_path = path;
+ ste++->ste_path = path;
}
/* grab all swap info */
swapctl(SC_LIST, swt);
@@ -351,21 +404,21 @@ double swapused(int *total, int *used)
i = cnt;
while (--i >= 0)
{
- /* dont count slots being deleted */
- if (!(ste->ste_flags & ST_INDEL) &&
- !(ste->ste_flags & ST_DOINGDEL))
- {
- *total += ste->ste_pages;
- free += ste->ste_free;
- }
- ste++;
+ /* dont count slots being deleted */
+ if (!(ste->ste_flags & ST_INDEL) &&
+ !(ste->ste_flags & ST_DOINGDEL))
+ {
+ *total += ste->ste_pages;
+ free += ste->ste_free;
+ }
+ ste++;
}
*used = *total - free;
if( total != 0)
- percent = (double)*used / (double)*total;
+ percent = (double)*used / (double)*total;
else
- percent = 0;
+ percent = 0;
return percent;
}
@@ -400,7 +453,7 @@ swapused(int *total, int *used)
#endif
-#if _freebsd_ || defined(Solaris)
+#if __FreeBSD__
int
cpuload(char *str)
@@ -419,7 +472,69 @@ cpuload(char *str)
}
#endif
-#ifdef linux
+
+#ifdef Solaris
+
+#include <kstat.h>
+#include <sys/param.h>
+
+#define loaddouble(la) ((double)(la) / FSCALE)
+
+int
+cpuload(char *str)
+{
+ kstat_ctl_t *kc;
+ kstat_t *ks;
+ kstat_named_t *kn;
+ double l[3] = {-1, -1, -1};
+
+ kc = kstat_open();
+
+ if( !kc ){
+ strcpy(str, "(unknown) ");
+ return -1;
+ }
+
+ ks = kstat_lookup( kc, "unix", 0, "system_misc");
+
+ if( kstat_read( kc, ks, 0) == -1){
+ strcpy( str, "( unknown ");
+ return -1;
+ }
+
+ kn = kstat_data_lookup( ks, "avenrun_1min" );
+
+ if( kn ) {
+ l[0] = loaddouble(kn->value.ui32);
+ }
+
+ kn = kstat_data_lookup( ks, "avenrun_5min" );
+
+ if( kn ) {
+ l[1] = loaddouble(kn->value.ui32);
+ }
+
+ kn = kstat_data_lookup( ks, "avenrun_15min" );
+
+ if( kn ) {
+ l[2] = loaddouble(kn->value.ui32);
+ }
+
+ if (str) {
+
+ if (l[0] != -1)
+ sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]);
+ else
+ strcpy(str, " (unknown) ");
+ }
+
+ kstat_close(kc);
+ return (int)l[0];
+}
+
+#endif
+
+#ifdef __linux__
int
cpuload(char *str)
{
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index e96ed86e..1233f74b 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -1259,7 +1259,11 @@ int make_connection_to_somebody(userinfo_t *uin, int timeout){
return -1;
}
length = sizeof(server);
+#if defined(Solaris) && __OS_MAJOR_VERSION__ == 5 && __OS_MINOR_VERSION__ < 7
+ if (getsockname(sock, (struct sockaddr *) & server, & length) < 0) {
+#else
if (getsockname(sock, (struct sockaddr *) & server, (socklen_t *) & length) < 0) {
+#endif
close(sock);
perror("sock name err");
unlockutmpmode();
@@ -1426,7 +1430,11 @@ my_talk(userinfo_t * uin, int fri_stat, char defact)
sock = make_connection_to_somebody(uin, 5);
+#if defined(Solaris) && __OS_MAJOR_VERSION__ == 5 && __OS_MINOR_VERSION__ < 7
+ msgsock = accept(sock, (struct sockaddr *) 0, 0);
+#else
msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0);
+#endif
if (msgsock == -1) {
perror("accept");
unlockutmpmode();
diff --git a/mbbsd/topsong.c b/mbbsd/topsong.c
index 073f0138..07931aa0 100644
--- a/mbbsd/topsong.c
+++ b/mbbsd/topsong.c
@@ -55,7 +55,7 @@ sortsong()
while (fgets(buf, 200, fp)) {
strtok(buf, "\n\r");
strip_blank(cbuf, buf);
- if (!cbuf[0] || !isprint2(cbuf[0]))
+ if (!cbuf[0] || !isprint2((int)cbuf[0]))
continue;
for (n = 0; n < MAX_SONGS && songs[n].name[0]; n++)
diff --git a/mbbsd/user.c b/mbbsd/user.c
index a7a1eced..675ccb39 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -914,7 +914,7 @@ ispersonalid(char *inid)
strlcpy(id, inid, sizeof(id));
i = cksum = 0;
- if (!isalpha(id[0]) && (strlen(id) != 10))
+ if (!isalpha((int)id[0]) && (strlen(id) != 10))
return 0;
if (!(id[1] == '1' || id[1] == '2'))
return 0;
@@ -930,12 +930,12 @@ ispersonalid(char *inid)
i++;
i += 10;
id[0] = i % 10 + '0';
- if (!isdigit(id[9]))
+ if (!isdigit((int)id[9]))
return 0;
cksum += (id[9] - '0') + (i / 10);
for (j = 0; j < 9; ++j) {
- if (!isdigit(id[j]))
+ if (!isdigit((int)id[j]))
return 0;
cksum += (id[j] - '0') * (9 - j);
}
@@ -1199,7 +1199,7 @@ static char *isvalidphone(char *phone)
{
int i;
for( i = 0 ; phone[i] != 0 ; ++i )
- if( !isdigit(phone[i]) )
+ if( !isdigit((int)phone[i]) )
return "請不要加分隔符號";
if (!removespace(phone) ||
strlen(phone) < 9 ||
diff --git a/pttbbs.mk b/pttbbs.mk
index 25d737d1..505806f4 100644
--- a/pttbbs.mk
+++ b/pttbbs.mk
@@ -2,9 +2,13 @@
# 定義基本初值
BBSHOME?= $(HOME)
BBSHOME?= /home/bbs
+
OS!= uname
+OS_MAJOR_VER!= uname -r|cut -d . -f 1
+OS_MINOR_VER!= uname -r|cut -d . -f 2
OSTYPE?= $(OS)
-CC?= gcc
+
+CC= gcc
CCACHE!= which ccache|sed -e 's/^.*\///'
PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include
PTT_LDFLAGS= -pipe -Wall -L/usr/local/lib
@@ -26,14 +30,17 @@ LIBS_Linux=
# SunOS特有的環境
CFLAGS_Solaris= -DSolaris -I/usr/local/include
LDFLAGS_Solaris= -L/usr/local/lib -L/usr/lib/
-LIBS_Solaris= -lnsl -lsocket -liconv
+LIBS_Solaris= -lnsl -lsocket -liconv -lkstat
+OS_FLAGS= -D__OS_MAJOR_VERSION__=$(OS_MAJOR_VER) \
+ -D__OS_MINOR_VERSION__=$(OS_MINOR_VER)
# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數
-PTT_CFLAGS+= $(CFLAGS_$(OSTYPE))
+PTT_CFLAGS+= $(CFLAGS_$(OSTYPE)) $(OS_FLAGS)
PTT_LDFLAGS+= $(LDFLAGS_$(OSTYPE))
PTT_LIBS+= $(LIBS_$(OSTYPE))
+
# 若有定義 PROFILING
.if defined(PROFILING)
PTT_CFLAGS+= -pg