]> granicus.if.org Git - nethack/commitdiff
Use const char * for read_simplemail 'mbox' param
authorMichael Meyer <me@entrez.cc>
Thu, 1 Sep 2022 01:42:02 +0000 (21:42 -0400)
committerPasi Kallinen <paxed@alt.org>
Thu, 1 Sep 2022 14:02:30 +0000 (17:02 +0300)
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.

include/extern.h
src/hacklib.c
src/mail.c

index c1234b84846e8a7662229ff4534f8d007cafbea2..467c561312539ca8272571385e2594f61a5769c7 100644 (file)
@@ -1057,7 +1057,6 @@ extern void strbuf_append(strbuf_t *, const char *);
 extern void strbuf_reserve(strbuf_t *, int);
 extern void strbuf_empty(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 void shuffle_int_array(int *, int);
 /* note: the snprintf CPP wrapper includes the "fmt" argument in "..."
index c5e6d9a2145ee43975ed9a4dff867d4f00c61fc4..ad513500a62dda0f8e853dfcdc6b32c6a53f9367 100644 (file)
@@ -74,7 +74,6 @@
         void            strbuf_reserve  (strbuf *, int)
         void            strbuf_empty    (strbuf *)
         void            strbuf_nl_to_crlf (strbuf_t *)
-        char *          nonconst        (const char *, char *)
         int             swapbits        (int, int, int)
         void            shuffle_int_array (int *, int)
         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 */
 int
 swapbits(int val, int bita, int bitb)
index 237210f3b04e2b35c1f26766640f4795e5ad34ab..6af05c37c153aa11910df9a49e1c59e05815b511 100644 (file)
@@ -45,7 +45,7 @@ static boolean md_stop(coord *, coord *);
 static boolean md_rush(struct monst *, int, int);
 static void newmail(struct mail_info *);
 #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
 
 #if !defined(UNIX) && !defined(VMS)
@@ -561,7 +561,7 @@ ckmailstatus(void)
 #if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
 
 void
-read_simplemail(char *mbox, boolean adminmsg)
+read_simplemail(const char *mbox, boolean adminmsg)
 {
     FILE* mb = fopen(mbox, "r");
     char curline[128], *msg;
@@ -662,15 +662,13 @@ ck_server_admin_msg(void)
 #ifdef SERVER_ADMIN_MSG
     static struct stat ost,nst;
     static long lastchk = 0;
-    char adminbuf[BUFSZ];
 
     if (g.moves < lastchk + SERVER_ADMIN_MSG_CKFREQ) return;
     lastchk = g.moves;
 
     if (!stat(SERVER_ADMIN_MSG, &nst)) {
         if (nst.st_mtime > ost.st_mtime)
-            read_simplemail(nonconst(SERVER_ADMIN_MSG, adminbuf,
-                                     sizeof adminbuf), TRUE);
+            read_simplemail(SERVER_ADMIN_MSG, TRUE);
         ost.st_mtime = nst.st_mtime;
     }
 #endif /* SERVER_ADMIN_MSG */