Prefer $LOGNAME over $USER, since the latter is deprecated, see environ(7). Pointed out by millert@ Fall back to getlogin() before defaulting to " ???".
Index: snake/snake.6 =================================================================== RCS file: /cvs/src/games/snake/snake.6,v retrieving revision 1.12 diff -u -p -r1.12 snake.6 --- snake/snake.6 27 Nov 2015 09:37:56 -0000 1.12 +++ snake/snake.6 29 Nov 2015 13:39:21 -0000 @@ -116,7 +116,7 @@ To see who wastes time playing snake, ru .Fl s . .Sh ENVIRONMENT .Bl -tag -width Ds -.It Ev USER +.It Ev LOGNAME Name displayed in high score file. .El .Sh FILES Index: snake/snake.c =================================================================== RCS file: /cvs/src/games/snake/snake.c,v retrieving revision 1.17 diff -u -p -r1.17 snake.c --- snake/snake.c 27 Nov 2015 09:37:56 -0000 1.17 +++ snake/snake.c 29 Nov 2015 13:39:21 -0000 @@ -985,7 +985,7 @@ int readscores(int create) { const char *home; - const char *user; + const char *name; const char *modstr; int modint; int ret; @@ -1019,13 +1019,17 @@ readscores(int create) if (ferror(sf)) err(1, "error reading %s", scorepath); - user = getenv("USER"); - if (user == NULL || *user == '\0') - user = "???"; + name = getenv("LOGNAME"); + if (name == NULL || *name == '\0') + name = getenv("USER"); + if (name == NULL || *name == '\0') + name = getlogin(); + if (name == NULL || *name == '\0') + name = " ???"; if (nscores > TOPN) nscores = TOPN; - strlcpy(scores[nscores].name, user, sizeof(scores[nscores].name)); + strlcpy(scores[nscores].name, name, sizeof(scores[nscores].name)); scores[nscores].score = 0; return 1; Index: tetris/scores.c =================================================================== RCS file: /cvs/src/games/tetris/scores.c,v retrieving revision 1.15 diff -u -p -r1.15 scores.c --- tetris/scores.c 26 Nov 2015 14:43:18 -0000 1.15 +++ tetris/scores.c 29 Nov 2015 13:39:21 -0000 @@ -217,10 +217,13 @@ thisuser(void) if (u[0]) return (u); - p = getlogin(); - if (p == NULL || *p == '\0') { + p = getenv("LOGNAME"); + if (p == NULL || *p == '\0') + p = getenv("USER"); + if (p == NULL || *p == '\0') + p = getlogin(); + if (p == NULL || *p == '\0') p = " ???"; - } strlcpy(u, p, sizeof(u)); return (u); } Index: tetris/tetris.6 =================================================================== RCS file: /cvs/src/games/tetris/tetris.6,v retrieving revision 1.18 diff -u -p -r1.18 tetris.6 --- tetris/tetris.6 25 Nov 2015 16:15:06 -0000 1.18 +++ tetris/tetris.6 29 Nov 2015 13:39:21 -0000 @@ -145,6 +145,11 @@ name, score, and how many points were sc Scores which are the highest on a given level are marked with asterisks .Dq * . +.Sh ENVIRONMENT +.Bl -tag -width Ds +.It Ev LOGNAME +Name displayed in high score file. +.El .Sh FILES .Bl -tag -width $HOME/.tetris.scores .It Pa $HOME/.tetris.scores