MCPcopy Create free account
hub / github.com/NetHack/NetHack / whoami

Function whoami

sys/unix/unixmain.c:556–586  ·  view source on GitHub ↗

returns True iff we set plname[] to username which contains a hyphen */

Source from the content-addressed store, hash-verified

554
555/* returns True iff we set plname[] to username which contains a hyphen */
556boolean
557whoami(void)
558{
559 /*
560 * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS
561 * 2. Use $USER or $LOGNAME (if 1. fails)
562 * 3. Use getlogin() (if 2. fails)
563 * The resulting name is overridden by command line options.
564 * If everything fails, or if the resulting name is some generic
565 * account like "games", "play", "player", "hack" then eventually
566 * we'll ask him.
567 * Note that we trust the user here; it is possible to play under
568 * somebody else's name.
569 */
570 if (!*svp.plname) {
571 register const char *s;
572
573 s = nh_getenv("USER");
574 if (!s || !*s)
575 s = nh_getenv("LOGNAME");
576 if (!s || !*s)
577 s = getlogin();
578
579 if (s && *s) {
580 (void) strncpy(svp.plname, s, sizeof svp.plname - 1);
581 if (strchr(svp.plname, '-'))
582 return TRUE;
583 }
584 }
585 return FALSE;
586}
587
588void
589sethanguphandler(void (*handler)(int))

Callers 1

mainFunction · 0.70

Calls 2

getloginFunction · 0.85
nh_getenvFunction · 0.50

Tested by

no test coverage detected