From ba39c14448dbd478ef92c7c05e19d12ced6c7177 Mon Sep 17 00:00:00 2001 From: jsm Date: Sat, 9 Sep 2000 09:37:58 +0000 Subject: Store copy of username with strdup rather than using a fixed length buffer. Also make initialization functions and arrays static. --- battlestar/init.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'battlestar/init.c') 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; { -- cgit v1.2.3