Subject: bin/6058: [PATCH] Backgammon: use names for error numbers, etc.
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 08/27/1998 15:19:22
>Number:         6058
>Category:       bin
>Synopsis:       [PATCH] Backgammon: use names for error numbers, etc.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 27 10:20:02 1998
>Last-Modified:
>Originator:     Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-08-19
>Environment:
[
System: Linux octomino 2.0.35 #1 Wed Aug 12 15:54:21 UTC 1998 i586 unknown
Architecture: i586
]
>Description:

The game backgammon uses fixed numeric values for signal numbers,
error numbers and open(2) flags, rather than the names defined in the
appropriate headers.  The patch below fixes this.

>How-To-Repeat:

>Fix:

diff -ruN backgammon/backgammon/main.c backgammon+/backgammon/main.c
--- backgammon/backgammon/main.c	Sun Mar 29 12:13:44 1998
+++ backgammon+/backgammon/main.c	Thu Aug 27 13:02:22 1998
@@ -112,7 +112,7 @@
 
 	/* initialization */
 	bflag = 2;		/* default no board */
-	signal(2, getout);	/* trap interrupts */
+	signal(SIGINT, getout);	/* trap interrupts */
 	if (tcgetattr(0, &old) == -1)	/* get old tty mode */
 		errexit("backgammon(gtty)");
 	noech = old;
@@ -212,7 +212,7 @@
 					else
 						writec('\n');
 					writel("Password:");
-					signal(14, getout);
+					signal(SIGALRM, getout);
 					cflag = 1;
 					alarm(10);
 					for (i = 0; i < 10; i++) {
diff -ruN backgammon/common_source/save.c backgammon+/common_source/save.c
--- backgammon/common_source/save.c	Fri Oct 10 11:22:11 1997
+++ backgammon+/common_source/save.c	Thu Aug 27 13:03:53 1998
@@ -42,9 +42,9 @@
 #endif
 #endif /* not lint */
 
-#include "back.h"
+#include <errno.h>
 
-extern int errno;
+#include "back.h"
 
 static char confirm[] = "Are you sure you want to leave now?";
 static char prompt[] = "Enter a file name:  ";
@@ -94,7 +94,7 @@
 			writec(*fs++);
 		}
 		*fs = '\0';
-		if ((fdesc = open(fname, 2)) == -1 && errno == 2) {
+		if ((fdesc = open(fname, O_RDWR)) == -1 && errno == ENOENT) {
 			if ((fdesc = creat(fname, 0700)) != -1)
 				break;
 		}
@@ -154,7 +154,7 @@
 {
 	int     fdesc;
 
-	if ((fdesc = open(s, 0)) == -1)
+	if ((fdesc = open(s, O_RDONLY)) == -1)
 		norec(s);
 	read(fdesc, board, sizeof board);
 	read(fdesc, off, sizeof off);
diff -ruN backgammon/teachgammon/teach.c backgammon+/teachgammon/teach.c
--- backgammon/teachgammon/teach.c	Fri Oct 10 11:22:16 1997
+++ backgammon+/teachgammon/teach.c	Thu Aug 27 13:04:46 1998
@@ -72,7 +72,7 @@
 {
 	int     i;
 
-	signal(2, getout);
+	signal(SIGINT, getout);
 	if (tcgetattr(0, &old) == -1)	/* get old tty mode */
 		errexit("teachgammon(gtty)");
 	noech = old;
>Audit-Trail:
>Unformatted: