X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/5a555a984855e94b0fc3c9154da6b65208ba2c70..5a1c62c6b8c4c4c2fa8649ae49a04e2ba5ef2c33:/cribbage/crib.c?ds=sidebyside diff --git a/cribbage/crib.c b/cribbage/crib.c index e7d9ce3d..dc9756b5 100644 --- a/cribbage/crib.c +++ b/cribbage/crib.c @@ -1,4 +1,4 @@ -/* $NetBSD: crib.c,v 1.10 1998/08/30 09:19:37 veego Exp $ */ +/* $NetBSD: crib.c,v 1.16 2001/12/06 11:59:45 blymn Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -43,12 +43,13 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: crib.c,v 1.10 1998/08/30 09:19:37 veego Exp $"); +__RCSID("$NetBSD: crib.c,v 1.16 2001/12/06 11:59:45 blymn Exp $"); #endif #endif /* not lint */ #include #include +#include #include #include #include @@ -69,6 +70,28 @@ main(argc, argv) BOOLEAN playing; FILE *f; int ch; + int fd; + int flags; + + f = fopen(_PATH_LOG, "a"); + if (f == NULL) + warn("fopen %s", _PATH_LOG); + if (f != NULL && fileno(f) < 3) + exit(1); + + /* Revoke setgid privileges */ + setgid(getgid()); + + /* Set close-on-exec flag on log file */ + if (f != NULL) { + fd = fileno(f); + flags = fcntl(fd, F_GETFD); + if (flags < 0) + err(1, "fcntl F_GETFD"); + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + err(1, "fcntl F_SETFD"); + } while ((ch = getopt(argc, argv, "eqr")) != -1) switch (ch) { @@ -89,7 +112,7 @@ main(argc, argv) initscr(); (void)signal(SIGINT, rint); - crmode(); + cbreak(); noecho(); Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0); @@ -109,7 +132,7 @@ main(argc, argv) mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); instructions(); - crmode(); + cbreak(); noecho(); clear(); refresh(); @@ -129,14 +152,12 @@ main(argc, argv) playing = (getuchar() == 'Y'); } while (playing); - if ((f = fopen(_PATH_LOG, "a")) != NULL) { + if (f != NULL) { (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n", getlogin(), cgames, pgames); (void) fclose(f); } bye(); - if (!f) - errx(1, "can't open %s", _PATH_LOG); exit(0); } @@ -175,8 +196,6 @@ makeboard() void gamescore() { - extern int Lastscore[]; - if (pgames || cgames) { mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames); mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames); @@ -343,7 +362,7 @@ void discard(mycrib) BOOLEAN mycrib; { - char *prompt; + const char *prompt; CARD crd; prcrib(mycrib, TRUE);