From 86289e36093c0d3839dddf963cea265b2e0192b4 Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 25 Nov 2023 08:58:26 -0700 Subject: [PATCH] remove a machinedep function --- rogue/init.c | 23 +++++++++++++++++------ rogue/machdep.c | 19 ------------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/rogue/init.c b/rogue/init.c index 7bdf15c..c95cc68 100644 --- a/rogue/init.c +++ b/rogue/init.c @@ -46,6 +46,9 @@ #include #include +#include /* getuid(2) */ +#include /* */ +#include /* getpwuid(3) */ #include "rogue.h" @@ -74,7 +77,6 @@ gid_t gid, egid; int init(int argc, char *argv[]) { - const char *pn; int seed; int fd; @@ -88,12 +90,21 @@ init(int argc, char *argv[]) close(fd); seed = 0; - pn = md_gln(); - if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) { - clean_up("Hey! Who are you?"); + { + char *ps; + struct passwd *p; + if((p = getpwuid(getuid())) != NULL + || strlen(p->pw_name) + >= (sizeof login_name) + / (sizeof *login_name)) + clean_up("Hey! Who are you?"); + else + ps = p->pw_name; + strncpy(login_name, ps, + (sizeof login_name)/(sizeof *login_name) - 1); + login_name[(sizeof login_name)/(sizeof *login_name) - 1] + = '\0'; } - /* LOGIN_NAME_SIZE == MAX_OPT_LEN now, but just in case... */ - (void)strlcpy(login_name, pn, sizeof(login_name)); do_args(argc, argv); do_opts(); diff --git a/rogue/machdep.c b/rogue/machdep.c index 734bb65..2f07ed7 100644 --- a/rogue/machdep.c +++ b/rogue/machdep.c @@ -294,25 +294,6 @@ md_df(const char *fname) return(1); } -/* md_gln: (Get login name) - * - * This routine returns the login name of the user. This string is - * used mainly for identifying users in score files. - * - * A dummy string may be returned if you are unable to implement this - * function, but then the score file would only have one name in it. - */ - -const char * -md_gln(void) -{ - struct passwd *p; - - if (!(p = getpwuid(getuid()))) - return NULL; - return p->pw_name; -} - /* md_sleep: * * This routine causes the game to pause for the specified number of