Subject: bin/6057: [PATCH] Canfield: use names for open(2) flags, etc.
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 08/27/1998 15:23:48
>Number:         6057
>Category:       bin
>Synopsis:       [PATCH] Canfield: use names for open(2) flags, 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:01 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 canfield uses numeric constants for open(2) flags and the
third argument of lseek(2), rather than the appropriate names for the
constants.  The appended patch fixes this.

>How-To-Repeat:

>Fix:

diff -ruN canfield/canfield/canfield.c canfield+/canfield/canfield.c
--- canfield/canfield/canfield.c	Sat Oct 11 11:51:03 1997
+++ canfield+/canfield/canfield.c	Thu Aug 27 15:10:53 1998
@@ -1427,7 +1427,7 @@
 	move(21, 0);
 	refresh();
 	if (dbfd != -1) {
-		lseek(dbfd, uid * sizeof(struct betinfo), 0);
+		lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
 		write(dbfd, (char *)&total, sizeof(total));
 	}
 	kill(getpid(), SIGTSTP);
@@ -1682,10 +1682,10 @@
 	uid = getuid();
 	if (uid < 0)
 		uid = 0;
-	dbfd = open(_PATH_SCORE, 2);
+	dbfd = open(_PATH_SCORE, O_RDWR);
 	if (dbfd < 0)
 		return;
-	i = lseek(dbfd, uid * sizeof(struct betinfo), 0);
+	i = lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
 	if (i < 0) {
 		close(dbfd);
 		dbfd = -1;
@@ -1749,7 +1749,7 @@
 	status = NOBOX;
 	updatebettinginfo();
 	if (dbfd != -1) {
-		lseek(dbfd, uid * sizeof(struct betinfo), 0);
+		lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET);
 		write(dbfd, (char *)&total, sizeof(total));
 		close(dbfd);
 	}
diff -ruN canfield/cfscores/cfscores.c canfield+/cfscores/cfscores.c
--- canfield/cfscores/cfscores.c	Sat Oct 11 11:51:07 1997
+++ canfield+/cfscores/cfscores.c	Thu Aug 27 15:11:29 1998
@@ -83,7 +83,7 @@
 		printf("Usage: cfscores [user]\n");
 		exit(1);
 	}
-	dbfd = open(_PATH_SCORE, 0);
+	dbfd = open(_PATH_SCORE, O_RDONLY);
 	if (dbfd < 0)
 		err(2, "open %s", _PATH_SCORE);
 	setpwent();
@@ -126,7 +126,7 @@
 		printf("Bad uid %d\n", pw->pw_uid);
 		return;
 	}
-	i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), 0);
+	i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), SEEK_SET);
 	if (i < 0)
 		warn("lseek %s", _PATH_SCORE);
 	i = read(dbfd, (char *)&total, sizeof(total));
>Audit-Trail:
>Unformatted: