Use const char * for read_simplemail 'mbox' param
Nothing about read_simplemail is incompatible with using const, and the lack of const required some contortions (copying ADMIN_SERVER_MSG to another buffer with nonconst() to prevent a compiler warning). This was the last place nonconst() was used, so I removed it.
This commit is contained in:
committed by
Pasi Kallinen
parent
b18d768b26
commit
51d568319b
@@ -1057,7 +1057,6 @@ extern void strbuf_append(strbuf_t *, const char *);
|
|||||||
extern void strbuf_reserve(strbuf_t *, int);
|
extern void strbuf_reserve(strbuf_t *, int);
|
||||||
extern void strbuf_empty(strbuf_t *);
|
extern void strbuf_empty(strbuf_t *);
|
||||||
extern void strbuf_nl_to_crlf(strbuf_t *);
|
extern void strbuf_nl_to_crlf(strbuf_t *);
|
||||||
extern char *nonconst(const char *, char *, size_t);
|
|
||||||
extern int swapbits(int, int, int);
|
extern int swapbits(int, int, int);
|
||||||
extern void shuffle_int_array(int *, int);
|
extern void shuffle_int_array(int *, int);
|
||||||
/* note: the snprintf CPP wrapper includes the "fmt" argument in "..."
|
/* note: the snprintf CPP wrapper includes the "fmt" argument in "..."
|
||||||
|
|||||||
@@ -74,7 +74,6 @@
|
|||||||
void strbuf_reserve (strbuf *, int)
|
void strbuf_reserve (strbuf *, int)
|
||||||
void strbuf_empty (strbuf *)
|
void strbuf_empty (strbuf *)
|
||||||
void strbuf_nl_to_crlf (strbuf_t *)
|
void strbuf_nl_to_crlf (strbuf_t *)
|
||||||
char * nonconst (const char *, char *)
|
|
||||||
int swapbits (int, int, int)
|
int swapbits (int, int, int)
|
||||||
void shuffle_int_array (int *, int)
|
void shuffle_int_array (int *, int)
|
||||||
void nh_snprintf (const char *, int, char *, size_t,
|
void nh_snprintf (const char *, int, char *, size_t,
|
||||||
@@ -1271,19 +1270,6 @@ strbuf_nl_to_crlf(strbuf_t *strbuf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
nonconst(const char *str, char *buf, size_t bufsz)
|
|
||||||
{
|
|
||||||
char *retval = emptystr;
|
|
||||||
|
|
||||||
if (str && buf)
|
|
||||||
if (strlen(str) <= (bufsz - 1)) {
|
|
||||||
Strcpy(buf, str);
|
|
||||||
retval = buf;
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* swapbits(val, bita, bitb) swaps bit a with bit b in val */
|
/* swapbits(val, bita, bitb) swaps bit a with bit b in val */
|
||||||
int
|
int
|
||||||
swapbits(int val, int bita, int bitb)
|
swapbits(int val, int bita, int bitb)
|
||||||
|
|||||||
+3
-5
@@ -45,7 +45,7 @@ static boolean md_stop(coord *, coord *);
|
|||||||
static boolean md_rush(struct monst *, int, int);
|
static boolean md_rush(struct monst *, int, int);
|
||||||
static void newmail(struct mail_info *);
|
static void newmail(struct mail_info *);
|
||||||
#if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
|
#if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
|
||||||
static void read_simplemail(char *mbox, boolean adminmsg);
|
static void read_simplemail(const char *mbox, boolean adminmsg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(UNIX) && !defined(VMS)
|
#if !defined(UNIX) && !defined(VMS)
|
||||||
@@ -561,7 +561,7 @@ ckmailstatus(void)
|
|||||||
#if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
|
#if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
|
||||||
|
|
||||||
void
|
void
|
||||||
read_simplemail(char *mbox, boolean adminmsg)
|
read_simplemail(const char *mbox, boolean adminmsg)
|
||||||
{
|
{
|
||||||
FILE* mb = fopen(mbox, "r");
|
FILE* mb = fopen(mbox, "r");
|
||||||
char curline[128], *msg;
|
char curline[128], *msg;
|
||||||
@@ -662,15 +662,13 @@ ck_server_admin_msg(void)
|
|||||||
#ifdef SERVER_ADMIN_MSG
|
#ifdef SERVER_ADMIN_MSG
|
||||||
static struct stat ost,nst;
|
static struct stat ost,nst;
|
||||||
static long lastchk = 0;
|
static long lastchk = 0;
|
||||||
char adminbuf[BUFSZ];
|
|
||||||
|
|
||||||
if (g.moves < lastchk + SERVER_ADMIN_MSG_CKFREQ) return;
|
if (g.moves < lastchk + SERVER_ADMIN_MSG_CKFREQ) return;
|
||||||
lastchk = g.moves;
|
lastchk = g.moves;
|
||||||
|
|
||||||
if (!stat(SERVER_ADMIN_MSG, &nst)) {
|
if (!stat(SERVER_ADMIN_MSG, &nst)) {
|
||||||
if (nst.st_mtime > ost.st_mtime)
|
if (nst.st_mtime > ost.st_mtime)
|
||||||
read_simplemail(nonconst(SERVER_ADMIN_MSG, adminbuf,
|
read_simplemail(SERVER_ADMIN_MSG, TRUE);
|
||||||
sizeof adminbuf), TRUE);
|
|
||||||
ost.st_mtime = nst.st_mtime;
|
ost.st_mtime = nst.st_mtime;
|
||||||
}
|
}
|
||||||
#endif /* SERVER_ADMIN_MSG */
|
#endif /* SERVER_ADMIN_MSG */
|
||||||
|
|||||||
Reference in New Issue
Block a user