diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-11-25 00:08:04 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-11-25 00:08:04 +0000 |
commit | 55822bc600173fabd3e8c1b51dfa50c89dc76686 (patch) | |
tree | dbca7be77c33bd8a1144c5a7eb5767d83c100d61 /games | |
parent | 7f259206334942367d8359a51cb7dc415dc32021 (diff) |
rindex -> strrchr
add some void casts
safe strcpy
Diffstat (limited to 'games')
-rw-r--r-- | games/dm/dm.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/games/dm/dm.c b/games/dm/dm.c index 690b0c62fa0..1f0acf7bc1d 100644 --- a/games/dm/dm.c +++ b/games/dm/dm.c @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: dm.c,v 1.5 1996/02/06 22:47:20 jtc Exp $"; +static char rcsid[] = "$OpenBSD: dm.c,v 1.4 1996/11/25 00:08:03 millert Exp $"; #endif #endif /* not lint */ @@ -77,7 +77,7 @@ main(argc, argv) char *cp; nogamefile(); - game = (cp = rindex(*argv, '/')) ? ++cp : *argv; + game = (cp = strrchr(*argv, '/')) ? ++cp : *argv; if (!strcmp(game, "dm")) exit(0); @@ -101,6 +101,11 @@ play(args) { char pbuf[MAXPATHLEN]; + if (sizeof(_PATH_HIDE) + strlen(game) > sizeof(pbuf)) { + (void)fprintf(stderr, "dm: %s/%s: %s\n", _PATH_HIDE, game, + strerror(ENAMETOOLONG)); + exit(1); + } (void)strcpy(pbuf, _PATH_HIDE); (void)strcpy(pbuf + sizeof(_PATH_HIDE) - 1, game); if (priority > 0) /* < 0 requires root */ @@ -168,11 +173,11 @@ c_day(s_day, s_start, s_stop) start = atoi(s_start); stop = atoi(s_stop); if (ct->tm_hour >= start && ct->tm_hour < stop) { - fputs("dm: Sorry, games are not available from ", stderr); + (void)fputs("dm: Sorry, games are not available from ", stderr); hour(start); - fputs(" to ", stderr); + (void)fputs(" to ", stderr); hour(stop); - fputs(" today.\n", stderr); + (void)fputs(" today.\n", stderr); exit(0); } } @@ -188,12 +193,12 @@ c_tty(tty) static char *p_tty; if (first) { - p_tty = rindex(gametty, '/'); + p_tty = strrchr(gametty, '/'); first = 0; } if (!strcmp(gametty, tty) || p_tty && !strcmp(p_tty, tty)) { - fprintf(stderr, "dm: Sorry, you may not play games on %s.\n", gametty); + (void)fprintf(stderr, "dm: Sorry, you may not play games on %s.\n", gametty); exit(0); } } @@ -214,11 +219,11 @@ c_game(s_game, s_load, s_users, s_priority) return; ++found; if (isdigit(*s_load) && atoi(s_load) < load()) { - fputs("dm: Sorry, the load average is too high right now.\n", stderr); + (void)fputs("dm: Sorry, the load average is too high right now.\n", stderr); exit(0); } if (isdigit(*s_users) && atoi(s_users) <= users()) { - fputs("dm: Sorry, there are too many users logged on right now.\n", stderr); + (void)fputs("dm: Sorry, there are too many users logged on right now.\n", stderr); exit(0); } if (isdigit(*s_priority)) @@ -235,7 +240,7 @@ load() double avenrun[3]; if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0) { - fputs("dm: getloadavg() failed.\n", stderr); + (void)fputs("dm: getloadavg() failed.\n", stderr); exit(1); } return(avenrun[2]); @@ -287,16 +292,16 @@ hour(h) { switch(h) { case 0: - fputs("midnight", stderr); + (void)fputs("midnight", stderr); break; case 12: - fputs("noon", stderr); + (void)fputs("noon", stderr); break; default: if (h > 12) - fprintf(stderr, "%dpm", h - 12); + (void)fprintf(stderr, "%dpm", h - 12); else - fprintf(stderr, "%dam", h); + (void)fprintf(stderr, "%dam", h); } } @@ -324,10 +329,10 @@ logfile() sleep((u_int)1); } if (pw = getpwuid(uid = getuid())) - fputs(pw->pw_name, lp); + (void)fputs(pw->pw_name, lp); else - fprintf(lp, "%u", uid); - fprintf(lp, "\t%s\t%s\t%s", game, gametty, ctime(&now)); + (void)fprintf(lp, "%u", uid); + (void)fprintf(lp, "\t%s\t%s\t%s", game, gametty, ctime(&now)); (void)flock(fileno(lp), LOCK_UN); (void)fclose(lp); } |