summaryrefslogtreecommitdiffstats
path: root/battlestar
diff options
context:
space:
mode:
authorjsm <jsm@NetBSD.org>2000-09-09 09:37:58 +0000
committerjsm <jsm@NetBSD.org>2000-09-09 09:37:58 +0000
commitba39c14448dbd478ef92c7c05e19d12ced6c7177 (patch)
treed365e7cf9cc7c3b41610dae6b9e399713b1aede8 /battlestar
parent964291ab94b8c99e06c7eb639459f9a62dabeb7c (diff)
downloadbsdgames-darwin-ba39c14448dbd478ef92c7c05e19d12ced6c7177.tar.gz
bsdgames-darwin-ba39c14448dbd478ef92c7c05e19d12ced6c7177.tar.zst
bsdgames-darwin-ba39c14448dbd478ef92c7c05e19d12ced6c7177.zip
Store copy of username with strdup rather than using a fixed length
buffer. Also make initialization functions and arrays static.
Diffstat (limited to 'battlestar')
-rw-r--r--battlestar/extern.h7
-rw-r--r--battlestar/globals.c6
-rw-r--r--battlestar/init.c29
3 files changed, 23 insertions, 19 deletions
diff --git a/battlestar/extern.h b/battlestar/extern.h
index 45477601..055466bd 100644
--- a/battlestar/extern.h
+++ b/battlestar/extern.h
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.18 2000/09/09 09:36:23 jsm Exp $ */
+/* $NetBSD: extern.h,v 1.19 2000/09/09 09:37:58 jsm Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -285,7 +285,7 @@ extern unsigned int wear[NUMOFWORDS];
extern char beenthere[NUMOFROOMS + 1];
extern char injuries[NUMOFINJURIES];
-extern char username[9];
+extern const char *username;
struct wlist {
const char *string;
@@ -310,7 +310,6 @@ extern const struct objs nightobjs[];
void blast __P((void));
void bury __P((void));
int card __P((const char *, int));
-int checkout __P((const char *));
void chime __P((void));
void convert __P((int));
void crash __P((void));
@@ -327,7 +326,6 @@ void endfly __P((void));
int fight __P((int, int));
int follow __P((void));
char *getcom __P((char *, int, const char *, const char *));
-void getutmp __P((char *));
char *getword __P((char *, char *, int));
int give __P((void));
int hash __P((const char *));
@@ -372,7 +370,6 @@ int use __P((void));
int visual __P((void));
int wearit __P((void));
void whichway __P((struct room));
-int wizard __P((const char *));
void wordinit __P((void));
void writedes __P((void));
int zzz __P((void));
diff --git a/battlestar/globals.c b/battlestar/globals.c
index 7c743715..17d9428d 100644
--- a/battlestar/globals.c
+++ b/battlestar/globals.c
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.c,v 1.10 2000/09/08 17:25:32 jsm Exp $ */
+/* $NetBSD: globals.c,v 1.11 2000/09/09 09:37:58 jsm Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: globals.c,v 1.10 2000/09/08 17:25:32 jsm Exp $");
+__RCSID("$NetBSD: globals.c,v 1.11 2000/09/09 09:37:58 jsm Exp $");
#endif
#endif /* not lint */
@@ -257,6 +257,6 @@ unsigned int wear[NUMOFWORDS];
char beenthere[NUMOFROOMS + 1];
char injuries[NUMOFINJURIES];
-char username[9];
+const char *username;
struct wlist *hashtab[HASHSIZE];
diff --git a/battlestar/init.c b/battlestar/init.c
index 854021a8..9670ea84 100644
--- a/battlestar/init.c
+++ b/battlestar/init.c
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.11 1999/09/18 16:47:11 jsm Exp $ */
+/* $NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,12 +38,16 @@
#if 0
static char sccsid[] = "@(#)init.c 8.4 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: init.c,v 1.11 1999/09/18 16:47:11 jsm Exp $");
+__RCSID("$NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $");
#endif
#endif /* not lint */
#include "extern.h"
+static int checkout __P((const char *));
+static const char *getutmp __P((void));
+static int wizard __P((const char *));
+
void
initialize(filename)
const char *filename;
@@ -56,7 +60,7 @@ initialize(filename)
puts("Admiral D.W. Riggle\n");
location = dayfile;
srand(getpid());
- getutmp(username);
+ username = getutmp();
wordinit();
if (filename == NULL) {
direction = NORTH;
@@ -77,17 +81,20 @@ initialize(filename)
signal(SIGINT, diesig);
}
-void
-getutmp(uname)
- char *uname;
+static const char *
+getutmp()
{
struct passwd *ptr;
ptr = getpwuid(getuid());
- strncpy(uname, ptr ? ptr->pw_name : "", 8);
+ if (ptr == NULL)
+ return "";
+ else
+ return strdup(ptr->pw_name);
}
-const char *const list[] = { /* hereditary wizards */
+/* Hereditary wizards. A configuration file might make more sense. */
+static const char *const list[] = {
"riggle",
"chris",
"edward",
@@ -98,14 +105,14 @@ const char *const list[] = { /* hereditary wizards */
0
};
-const char *const badguys[] = {
+static const char *const badguys[] = {
"wnj",
"root",
"ted",
0
};
-int
+static int
wizard(uname)
const char *uname;
{
@@ -116,7 +123,7 @@ wizard(uname)
return flag;
}
-int
+static int
checkout(uname)
const char *uname;
{