Book: always use Write* API to write into binbook.
authorYann Dirson <ydirson@free.fr>
Fri, 21 Feb 2014 21:37:55 +0000 (22:37 +0100)
committerYann Dirson <ydirson@free.fr>
Sat, 22 Feb 2014 09:46:23 +0000 (10:46 +0100)
Makes it easier to factorise error handling.

gnushogi/book.c

index 83c9ef2..4445c47 100644 (file)
@@ -638,7 +638,7 @@ GetOpenings(void)
 {
     ULONG currentoffset = 0;
     short i;
-    int mustwrite = false, first;
+    int first;
     unsigned short side;
     short c;
     USHORT mv, flags;
@@ -694,18 +694,20 @@ GetOpenings(void)
             DATA.flags = 0;
             DATA.hint = 0;
             DATA.count = 0;
-            write(gfd, (char *)&ADMIN, sizeof_gdxadmin);
+            WriteAdmin();
             printf("creating bookfile %s %ld %ld\n",
                     binbookfile, B.maxoffset, B.booksize);
 
             for (x = 0; x < B.booksize; x++)
             {
-                write(gfd, (char *)&DATA, sizeof_gdxdata);
+                int mustwrite = true;
+                WriteData(sizeof_gdxadmin + x* sizeof_gdxdata, &mustwrite);
             }
         }
 
         if (gfd >= 0)
         {
+            int mustwrite = false;
             /* setvbuf(fd, buffr, _IOFBF, 2048); */
             side = black;
             hashbd = hashkey = 0;