X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/90f5663ccbe92953f9eea2ee004653a52ca7196d..a4d00d5b72c57ebc93b5b96dc673894fe97cd0e7:/atc/main.c?ds=sidebyside diff --git a/atc/main.c b/atc/main.c index 898a7fa2..49c5d6aa 100644 --- a/atc/main.c +++ b/atc/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.15 2005/08/10 17:53:28 rpaulo Exp $ */ +/* $NetBSD: main.c,v 1.20 2009/08/12 04:48:03 dholland Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -43,15 +43,15 @@ #include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +__COPYRIGHT("@(#) Copyright (c) 1990, 1993\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.15 2005/08/10 17:53:28 rpaulo Exp $"); +__RCSID("$NetBSD: main.c,v 1.20 2009/08/12 04:48:03 dholland Exp $"); #endif #endif /* not lint */ @@ -60,10 +60,15 @@ __RCSID("$NetBSD: main.c,v 1.15 2005/08/10 17:53:28 rpaulo Exp $"); extern FILE *yyin; +static int read_file(const char *); +static const char *default_game(void); +static const char *okay_game(const char *); +static int list_games(void); + int main(int argc, char *argv[]) { - int seed; + unsigned long seed; int f_usage = 0, f_list = 0, f_showscore = 0; int f_printpath = 0; const char *file = NULL; @@ -77,9 +82,10 @@ main(int argc, char *argv[]) open_score_file(); (void)setgid(getgid()); - start_time = seed = time(NULL); + start_time = time(NULL); + seed = start_time; - while ((ch = getopt(argc, argv, "ulstpg:f:r:")) != -1) { + while ((ch = getopt(argc, argv, ":u?lstpg:f:r:")) != -1) { switch (ch) { case '?': case 'u': @@ -107,7 +113,7 @@ main(int argc, char *argv[]) } if (optind < argc) f_usage++; - srandom((unsigned long)seed); + srandom(seed); if (f_usage) (void)fprintf(stderr, @@ -120,8 +126,7 @@ main(int argc, char *argv[]) if (f_printpath) { char buf[100]; - (void)strcpy(buf, _PATH_GAMES); - buf[strlen(buf) - 1] = '\0'; + (void)strlcpy(buf, _PATH_GAMES, 100); (void)puts(buf); } @@ -145,7 +150,6 @@ main(int argc, char *argv[]) (void)signal(SIGQUIT, quit); #ifdef BSD (void)signal(SIGTSTP, SIG_IGN); - (void)signal(SIGSTOP, SIG_IGN); #endif (void)signal(SIGHUP, log_score_quit); (void)signal(SIGTERM, log_score_quit); @@ -205,7 +209,7 @@ main(int argc, char *argv[]) } } -int +static int read_file(const char *s) { int retval; @@ -225,15 +229,15 @@ read_file(const char *s) return (0); } -const char * +static const char * default_game(void) { FILE *fp; static char file[256]; char line[256], games[256]; - (void)strcpy(games, _PATH_GAMES); - (void)strcat(games, GAMES); + (void)strlcpy(games, _PATH_GAMES, 256); + (void)strlcat(games, GAMES, 256); if ((fp = fopen(games, "r")) == NULL) { warn("fopen %s", games); @@ -241,16 +245,17 @@ default_game(void) } if (fgets(line, sizeof(line), fp) == NULL) { (void)fprintf(stderr, "%s: no default game available\n", games); + fclose(fp); return (NULL); } (void)fclose(fp); line[strlen(line) - 1] = '\0'; - (void)strcpy(file, _PATH_GAMES); - (void)strcat(file, line); + (void)strlcpy(file, _PATH_GAMES, 256); + (void)strlcat(file, line, 256); return (file); } -const char * +static const char * okay_game(const char *s) { FILE *fp; @@ -258,8 +263,8 @@ okay_game(const char *s) const char *ret = NULL; char line[256], games[256]; - (void)strcpy(games, _PATH_GAMES); - (void)strcat(games, GAMES); + (void)strlcpy(games, _PATH_GAMES, 256); + (void)strlcat(games, GAMES, 256); if ((fp = fopen(games, "r")) == NULL) { warn("fopen %s", games); @@ -268,8 +273,8 @@ okay_game(const char *s) while (fgets(line, sizeof(line), fp) != NULL) { line[strlen(line) - 1] = '\0'; if (strcmp(s, line) == 0) { - (void)strcpy(file, _PATH_GAMES); - (void)strcat(file, line); + (void)strlcpy(file, _PATH_GAMES, 256); + (void)strlcat(file, line, 256); ret = file; break; } @@ -285,15 +290,15 @@ okay_game(const char *s) return (ret); } -int +static int list_games(void) { FILE *fp; char line[256], games[256]; int num_games = 0; - (void)strcpy(games, _PATH_GAMES); - (void)strcat(games, GAMES); + (void)strlcpy(games, _PATH_GAMES, 256); + (void)strlcat(games, GAMES, 256); if ((fp = fopen(games, "r")) == NULL) { warn("fopen %s", games);