chiark / gitweb /
fix up compilation errors
[chiark-tcl.git] / cdb / writeable.c
index 94a7f76a904fd4f7de81477d34c6f8a2985bd85e..6259ea05ea9803a41b619896cc56771774bbbeeb 100644 (file)
@@ -1,4 +1,22 @@
-/**/
+/*
+ * cdb, cdb-wr - Tcl bindings for tinycdb and a journalling write extension
+ * Copyright 2006 Ian Jackson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
 
 #include "chiark_tcl_cdb.h"
 
@@ -311,7 +329,7 @@ static int writerecord(FILE *f, const char *key, const HashValue *val) {
 
 int cht_do_cdbwr_create_empty(ClientData cd, Tcl_Interp *ip,
                              const char *pathb) {
-  static const char *const toremoves[]= { ".cdb", ".log", ".tmp", 0 };
+  static const char *const toremoves[]= { ".cdb", ".jrn", ".tmp", 0 };
 
   Pathbuf pb, pbmain;
   int lock_fd=-1, rc, r;
@@ -452,24 +470,24 @@ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb,
     PE("open .cdb");
   }
 
-  rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".log"), "r+");
+  rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".jrn"), "r+");
   if (!rw->logfile) {
-    if (errno != ENOENT) PE("failed to open .log during open");
+    if (errno != ENOENT) PE("failed to open .jrn during open");
     rw->logfile= fopen(rw->pbsome.buf, "w");
-    if (!rw->logfile) PE("create .log during (clean) open");
+    if (!rw->logfile) PE("create .jrn during (clean) open");
   } else { /* rw->logfile */
     r= fstat(fileno(rw->logfile), &stab);
-    if (r==-1) PE("fstat .log during open");
+    if (r==-1) PE("fstat .jrn during open");
     rc= infocb(ip, rw, "open-dirty-start", "log=%luby",
               (unsigned long)stab.st_size);
     if (rc) goto x_rc;
 
     for (;;) {
       logrecstart= ftello(rw->logfile);
-      if (logrecstart < 0) PE("ftello .log during (dirty) open");
+      if (logrecstart < 0) PE("ftello .jrn during (dirty) open");
       r= readstorelogrecord(rw->logfile, &rw->logincore, 0,0, ht_update);
       if (ferror(rw->logfile)) {
-       rc= cht_posixerr(ip, errno, "error reading .log during (dirty) open");
+       rc= cht_posixerr(ip, errno, "error reading .jrn during (dirty) open");
        goto x_rc;
       }
       if (r==-1) {
@@ -477,7 +495,7 @@ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb,
       } else if (r==-2 || r==-3) {
        char buf[100];
        logjunkpos= ftello(rw->logfile);
-       if(logjunkpos<0) PE("ftello .log during report of junk in dirty open");
+       if(logjunkpos<0) PE("ftello .jrn during report of junk in dirty open");
 
        snprintf(buf,sizeof(buf), "CDB SYNTAX LOG %lu %lu",
                 (unsigned long)logjunkpos, (unsigned long)logrecstart);
@@ -486,7 +504,7 @@ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb,
          Tcl_SetObjErrorCode(ip, Tcl_NewStringObj(buf,-1));
          snprintf(buf,sizeof(buf),"%lu",(unsigned long)logjunkpos);
          Tcl_ResetResult(ip);
-         Tcl_AppendResult(ip, "syntax error (junk) in .log during"
+         Tcl_AppendResult(ip, "syntax error (junk) in .jrn during"
                           " (dirty) open, at file position ", buf, (char*)0);
          rc= TCL_ERROR;
          goto x_rc;
@@ -496,10 +514,10 @@ int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb,
        if (rc) goto x_rc;
 
        r= fseeko(rw->logfile, logrecstart, SEEK_SET);
-       if (r) PE("failed to fseeko .log before junk during dirty open");
+       if (r) PE("failed to fseeko .jrn before junk during dirty open");
 
        r= ftruncate(fileno(rw->logfile), logrecstart);
-       if (r) PE("ftruncate .log to chop junk during dirty open");
+       if (r) PE("ftruncate .jrn to chop junk during dirty open");
       } else {
        assert(!r);
       }
@@ -572,7 +590,7 @@ static int compact_core(Tcl_Interp *ip, Rw *rw, unsigned long logsz,
                        long *reccount_r) {
   /* creates new .cdb and .main
    * closes logfile
-   * leaves .log with old data
+   * leaves .jrn with old data
    * leaves cdb fd open onto old db
    * leaves logincore full of crap
    */
@@ -728,8 +746,8 @@ static int compact_forclose(Tcl_Interp *ip, Rw *rw, long *reccount_r) {
 
   rc= compact_core(ip, rw, logsz, reccount_r);  if (rc) goto x_rc;
 
-  r= remove(pathbuf_sfx(&rw->pbsome,".log"));
-  if (r) PE("remove .log (during tidy close)");
+  r= remove(pathbuf_sfx(&rw->pbsome,".jrn"));
+  if (r) PE("remove .jrn (during tidy close)");
 
   return TCL_OK;
 
@@ -776,7 +794,7 @@ static int compact_keepopen(Tcl_Interp *ip, Rw *rw, int force) {
   int rc, r;
 
   logsz= ftello(rw->logfile);
-  if (logsz < 0) return cht_posixerr(ip, errno, "ftell .log"
+  if (logsz < 0) return cht_posixerr(ip, errno, "ftell .jrn"
                                       " during compact check or force");
 
   if (!force && logsz < rw->mainsz / 3 + 1000) return TCL_OK;
@@ -802,10 +820,10 @@ static int compact_keepopen(Tcl_Interp *ip, Rw *rw, int force) {
 
   rc= cdbinit(ip, rw);  if (rc) goto x_rc;
 
-  rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".log"), "w");
-  if (!rw->logfile) PE("reopen .log after compact");
+  rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".jrn"), "w");
+  if (!rw->logfile) PE("reopen .jrn after compact");
 
-  r= fsync(fileno(rw->logfile));  if (r) PE("fsync .log after compact reopen");
+  r= fsync(fileno(rw->logfile));  if (r) PE("fsync .jrn after compact reopen");
 
   return TCL_OK;
 
@@ -917,9 +935,3 @@ int cht_do_cdbwr_lookup_hb(ClientData cd, Tcl_Interp *ip, void *rw_v,
   return cht_cdb_donesomelookup(ip, rw_v, def, result, data, dlen,
                                cht_cdb_storeanswer_hb);
 }
-
-int cht_do_cdbtoplevel_cdb_wr(ClientData cd, Tcl_Interp *ip,
-                             const Cdbwr_SubCommand* subcmd,
-                             int objc, Tcl_Obj *const *objv) {
-  return subcmd->func((void*)subcmd,ip,objc,objv);
-}