-/* $NetBSD: fish.c,v 1.4 1997/10/10 12:58:32 lukem Exp $ */
+/* $NetBSD: fish.c,v 1.7 1999/04/24 22:09:06 kristerw Exp $ */
/*-
* Copyright (c) 1990, 1993
#if 0
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fish.c,v 1.4 1997/10/10 12:58:32 lukem Exp $");
+__RCSID("$NetBSD: fish.c,v 1.7 1999/04/24 22:09:06 kristerw Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
-#include <sys/errno.h>
+#include <sys/wait.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#include <time.h>
+#include <err.h>
#include "pathnames.h"
#define RANKS 13
void printhand __P((int *));
void printplayer __P((int));
int promove __P((void));
-void usage __P((void));
+void usage __P((void)) __attribute__((__noreturn__));
int usermove __P((void));
int
for (;;) {
(void)printf("You ask me for: ");
(void)fflush(stdout);
- if (fgets(buf, BUFSIZ, stdin) == NULL)
+ if (fgets(buf, sizeof(buf), stdin) == NULL)
exit(0);
if (buf[0] == '\0')
continue;
instructions()
{
int input;
- char buf[1024];
+ pid_t pid;
+ int status;
(void)printf("Would you like instructions (y or n)? ");
input = getchar();
if (input != 'y')
return;
- (void)sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR);
- (void)system(buf);
+ switch (pid = fork()) {
+ case 0: /* child */
+ (void)setuid(getuid());
+ (void)setgid(getgid());
+ (void)execl(_PATH_MORE, "more", _PATH_INSTR, NULL);
+ err(1, "%s %s", _PATH_MORE, _PATH_INSTR);
+ /*NOTREACHED*/
+ case -1:
+ err(1, "fork");
+ /*NOTREACHED*/
+ default:
+ (void)waitpid(pid, &status, 0);
+ break;
+ }
(void)printf("Hit return to continue...\n");
while ((input = getchar()) != EOF && input != '\n');
}