returns True iff we set plname[] to username which contains a hyphen */
| 554 | |
| 555 | /* returns True iff we set plname[] to username which contains a hyphen */ |
| 556 | boolean |
| 557 | whoami(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 | |
| 588 | void |
| 589 | sethanguphandler(void (*handler)(int)) |