X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/c57fa9b1accc28bd366bc1236a0a39ec8aea5130..4842cad26009ebcd3c2e39d529d0f4908599a7b5:/larn/main.c?ds=sidebyside diff --git a/larn/main.c b/larn/main.c index d386ed36..41a1498c 100644 --- a/larn/main.c +++ b/larn/main.c @@ -1,9 +1,9 @@ -/* $NetBSD: main.c,v 1.13 1998/07/27 01:12:35 mycroft Exp $ */ +/* $NetBSD: main.c,v 1.16 2001/02/05 00:57:33 christos Exp $ */ /* main.c */ #include #ifndef lint -__RCSID("$NetBSD: main.c,v 1.13 1998/07/27 01:12:35 mycroft Exp $"); +__RCSID("$NetBSD: main.c,v 1.16 2001/02/05 00:57:33 christos Exp $"); #endif /* not lint */ #include @@ -62,6 +62,7 @@ main(argc, argv) const char *ptr = 0; struct passwd *pwe; + i = 0; euid = geteuid(); uid = getuid(); seteuid(uid); /* give up "games" if we have it */ @@ -72,15 +73,17 @@ main(argc, argv) init_term(); /* setup the terminal (find out what type) * for termcap */ #endif /* VT100 */ - if (((ptr = getlogin()) == 0) || (*ptr == 0)) /* try to get login name */ - if ((pwe = getpwuid(getuid())) != NULL)/* can we get it from - * /etc/passwd? */ + /* try to get login name */ + if (((ptr = getlogin()) == 0) || (*ptr == 0)) { + /* can we get it from /etc/passwd? */ + if ((pwe = getpwuid(getuid())) != NULL) ptr = pwe->pw_name; else if ((ptr = getenv("USER")) == 0) if ((ptr = getenv("LOGNAME")) == 0) { noone: write(2, "Can't find your logname. Who Are You?\n", 39); exit(1); } + } if (ptr == 0) goto noone; if (strlen(ptr) == 0) @@ -97,7 +100,8 @@ main(argc, argv) strcpy(savefilename, ptr); strcat(savefilename, "/Larn.sav"); /* save file name in home * directory */ - sprintf(optsfile, "%s/.larnopts", ptr); /* the .larnopts filename */ + snprintf(optsfile, sizeof(optsfile), "%s/.larnopts", ptr); + /* the .larnopts filename */ /* * now malloc the memory for the dungeon @@ -1201,7 +1205,7 @@ eatcookie() while (1) { if ((i = whatitem("eat")) == '\33') return; - if (i != '.') + if (i != '.') { if (i == '*') showeat(); else { @@ -1223,6 +1227,7 @@ eatcookie() lprcat("\nYou can't eat that!"); return; } + } } } @@ -1268,7 +1273,7 @@ whatitem(str) lprintf("\nWhat do you want to %s [* for all] ? ", str); i = 0; while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.')) - i = getchar(); + i = lgetchar(); if (i == '\33') lprcat(" aborted"); return (i); @@ -1285,7 +1290,7 @@ readnum(mx) int i; unsigned long amt = 0; sncbr(); - if ((i = getchar()) == '*') + if ((i = lgetchar()) == '*') amt = mx; /* allow him to say * for all gold */ else while (i != '\n') { @@ -1296,7 +1301,7 @@ readnum(mx) } if ((i <= '9') && (i >= '0') && (amt < 99999999)) amt = amt * 10 + i - '0'; - i = getchar(); + i = lgetchar(); } scbr(); return (amt);