chiark
/
gitweb
/
~ian
/
chiark-tcl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
wiringpi module in changelog
[chiark-tcl.git]
/
cdb
/
writeable.c
diff --git
a/cdb/writeable.c
b/cdb/writeable.c
index 02c98cb8ad773230984f454f02f8b3205d826213..6b072ffdba7042398965758dc6ad386b18c15a5b 100644
(file)
--- a/
cdb/writeable.c
+++ b/
cdb/writeable.c
@@
-1,6
+1,6
@@
/*
* cdb, cdb-wr - Tcl bindings for tinycdb and a journalling write extension
/*
* cdb, cdb-wr - Tcl bindings for tinycdb and a journalling write extension
- * Copyright 2006 Ian Jackson
+ * Copyright 2006
-2012
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
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-13,9
+13,7
@@
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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.
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "chiark_tcl_cdb.h"
*/
#include "chiark_tcl_cdb.h"
@@
-170,13
+168,17
@@
typedef struct Rw {
ScriptToInvoke on_info, on_lexminval;
} Rw;
ScriptToInvoke on_info, on_lexminval;
} Rw;
+static void rw_cdb_close(Tcl_Interp *ip, Rw *rw) {
+ if (rw->cdb_fd >= 0) cdb_free(&rw->cdb);
+ maybe_close(rw->cdb_fd);
+}
+
static int rw_close(Tcl_Interp *ip, Rw *rw) {
int rc, r;
rc= TCL_OK;
ht_destroy(&rw->logincore);
static int rw_close(Tcl_Interp *ip, Rw *rw) {
int rc, r;
rc= TCL_OK;
ht_destroy(&rw->logincore);
- if (rw->cdb_fd >= 0) cdb_free(&rw->cdb);
- maybe_close(rw->cdb_fd);
+ rw_cdb_close(ip,rw);
maybe_close(rw->lock_fd);
if (rw->logfile) {
maybe_close(rw->lock_fd);
if (rw->logfile) {
@@
-414,7
+416,7
@@
static int infocb(Tcl_Interp *ip, Rw *rw, const char *arg1,
/*---------- Opening ----------*/
static int cdbinit(Tcl_Interp *ip, Rw *rw) {
/*---------- Opening ----------*/
static int cdbinit(Tcl_Interp *ip, Rw *rw) {
- /* On entry, cdb_fd >=0 but cdb is _undefined_
/
+ /* On entry, cdb_fd >=0 but cdb is _undefined_
* On exit, either cdb_fd<0 or cdb is initialised */
int r, rc;
* On exit, either cdb_fd<0 or cdb is initialised */
int r, rc;
@@
-813,8
+815,7
@@
static int compact_keepopen(Tcl_Interp *ip, Rw *rw, int force) {
rc= compact_core(ip, rw, logsz, &reccount); if (rc) goto x_rc;
rc= compact_core(ip, rw, logsz, &reccount); if (rc) goto x_rc;
- maybe_close(rw->cdb_fd);
- rw->cdb_fd= -1;
+ rw_cdb_close(ip,rw);
ht_destroy(&rw->logincore);
ht_setup(&rw->logincore);
ht_destroy(&rw->logincore);
ht_setup(&rw->logincore);
@@
-948,11
+949,18
@@
static int lookup_rw(Tcl_Interp *ip, void *rw_v, const char *key,
val= ht_lookup(&rw->logincore, key);
if (val) {
if (val->len) { *data_r= val->data; *len_r= val->len; return TCL_OK; }
val= ht_lookup(&rw->logincore, key);
if (val) {
if (val->len) { *data_r= val->data; *len_r= val->len; return TCL_OK; }
- else
{ *data_r= 0; *len_r= -1; return TCL_OK; }
+ else
goto not_found;
}
}
+ if (rw->cdb_fd<0) goto not_found;
+
return cht_cdb_lookup_cdb(ip, &rw->cdb, key, strlen(key), data_r, len_r);
return cht_cdb_lookup_cdb(ip, &rw->cdb, key, strlen(key), data_r, len_r);
-}
+
+ not_found:
+ *data_r= 0;
+ *len_r= -1;
+ return TCL_OK;
+}
int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
const char *key, Tcl_Obj *def,
int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
const char *key, Tcl_Obj *def,