Hi!

Sending patches while your better half is screaming doesn't work too well, 
tedu@ already commited my changes for canfield(6), but they had a few stupid 
lseek(), although still needed, that no one probably would notice except theo@

Since the score file now only has 1 record, instead of 1 record per each uid 
like before, then the lseek needs to point to the beginning of the file and 
additionally if there's a open(2) then the immediate lseek is not needed.

ndex: canfield/canfield.c
===================================================================
RCS file: /cvs/src/games/canfield/canfield/canfield.c,v
retrieving revision 1.17
diff -u -p -u -r1.17 canfield.c
--- canfield/canfield.c 24 Nov 2015 02:53:39 -0000      1.17
+++ canfield/canfield.c 24 Nov 2015 10:59:32 -0000
@@ -1377,7 +1377,7 @@ suspend(void)
        move(21, 0);
        refresh();
        if (dbfd != -1) {
-               lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
+               lseek(dbfd, 0, SEEK_SET);
                write(dbfd, (char *)&total, sizeof(total));
        }
        kill(getpid(), SIGTSTP);
@@ -1635,12 +1635,6 @@ initall(void)
        dbfd = open(scorepath, O_RDWR | O_CREAT, 0644);
        if (dbfd < 0)
                return;
-       i = lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
-       if (i < 0) {
-               close(dbfd);
-               dbfd = -1;
-               return;
-       }
        i = read(dbfd, (char *)&total, sizeof(total));
        if (i < 0) {
                close(dbfd);
@@ -1698,7 +1692,7 @@ cleanup(int dummy)
        status = NOBOX;
        updatebettinginfo();
        if (dbfd != -1) {
-               lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
+               lseek(dbfd, 0, SEEK_SET);
                write(dbfd, (char *)&total, sizeof(total));
                close(dbfd);
        }
Index: cfscores/cfscores.c
===================================================================
RCS file: /cvs/src/games/canfield/cfscores/cfscores.c,v
retrieving revision 1.17
diff -u -p -u -r1.17 cfscores.c
--- cfscores/cfscores.c 24 Nov 2015 02:53:39 -0000      1.17
+++ cfscores/cfscores.c 24 Nov 2015 10:59:43 -0000
@@ -91,11 +91,6 @@ printuser(const struct passwd *pw, int p
                printf("Bad uid %u\n", pw->pw_uid);
                return;
        }
-       i = lseek(dbfd, sizeof(struct betinfo), SEEK_SET);
-       if (i < 0) {
-               warn("lseek %s", scorepath);
-               return;
-       }
        i = read(dbfd, (char *)&total, sizeof(total));
        if (i < 0) {
                warn("lseek %s", scorepath);

Reply via email to