summaryrefslogtreecommitdiff
path: root/support/dktools/dk4dbi.c
diff options
context:
space:
mode:
Diffstat (limited to 'support/dktools/dk4dbi.c')
-rw-r--r--support/dktools/dk4dbi.c392
1 files changed, 239 insertions, 153 deletions
diff --git a/support/dktools/dk4dbi.c b/support/dktools/dk4dbi.c
index f7c3a349ad..d66e04ff79 100644
--- a/support/dktools/dk4dbi.c
+++ b/support/dktools/dk4dbi.c
@@ -1,43 +1,21 @@
/*
- WARNING: This file was generated by dkct.
- Changes you make here will be lost if dkct is run again!
- You should modify the original source and run dkct on it.
- Original source: dk4dbi.ctr
+Copyright (C) 2015-2020, Dirk Krause
+SPDX-License-Identifier: BSD-3-Clause
*/
/*
-Copyright (C) 2015-2017, Dirk Krause
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above opyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-* Neither the name of the author nor the names of contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ WARNING: This file was generated by the dkct program (see
+ http://dktools.sourceforge.net/ for details).
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: dk4dbi.ctr
*/
/** @file dk4dbi.c The dk4dbi module.
*/
-#line 556 "dk4dbi.ctr"
+#line 576 "dk4dbi.ctr"
#include "dk4conf.h"
@@ -55,6 +33,13 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#endif
+#if DK4_HAVE_ASSERT_H
+#ifndef ASSERT_H_INCLUDED
+#include <assert.h>
+#define ASSERT_H_INCLUDED 1
+#endif
+#endif
+
#include "dk4dbi.h"
#include "dk4mem.h"
#include "dk4memrs.h"
@@ -67,12 +52,14 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dk4delfile.h"
#include "dk4stat.h"
#include "dk4statd.h"
+#include "dk4maadu.h"
+#include "dk4unused.h"
-#line 589 "dk4dbi.ctr"
+#line 618 "dk4dbi.ctr"
@@ -102,22 +89,23 @@ dkT("ndbm"),
NULL
-#line 611 "dk4dbi.ctr"
+#line 640 "dk4dbi.ctr"
};
/** File name suffixes for NDBM files.
*/
+
+#if (DK4_CHAR_SIZE == 1) \
+&& (\
+ (DK4_HAVE_NDBM_H) \
+ || ((!(DK4_ON_WINDOWS)) && (DK4_HAVE_CHOWN) && (DK4_HAVE_CHMOD))\
+)
static const dkChar *dk4dbi_ndbm_suffixes[] = {
dkT(".dir"), dkT(".pag")
};
-
-
-
-/** Maximum size of key or value.
-*/
-static const unsigned long dk4dbi_max_size = 4294967295UL;
+#endif
@@ -134,14 +122,17 @@ dk4dbi_datum_delete(dk4_dbi_datum_t *ptr, int options)
int back = 0;
-#line 641 "dk4dbi.ctr"
+#line 671 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != ptr);
+#endif
if (NULL != ptr) {
back = 1;
if (0 != (DK4_DB_OPT_RESET_KEY & options)) {
if ((NULL != ptr->kd) && ((size_t)0UL < ptr->ks)) {
-#line 646 "dk4dbi.ctr"
+#line 679 "dk4dbi.ctr"
if (0 == dk4mem_reset_secure(ptr->kd, ptr->ks, NULL)) {
back = 0;
}
@@ -151,7 +142,7 @@ dk4dbi_datum_delete(dk4_dbi_datum_t *ptr, int options)
if ((NULL != ptr->vd) && ((size_t)0UL < ptr->vs)) {
-#line 654 "dk4dbi.ctr"
+#line 687 "dk4dbi.ctr"
if (0 == dk4mem_reset_secure(ptr->vd, ptr->vs, NULL)) {
back = 0;
}
@@ -164,13 +155,14 @@ dk4dbi_datum_delete(dk4_dbi_datum_t *ptr, int options)
}
-#line 665 "dk4dbi.ctr"
+#line 698 "dk4dbi.ctr"
return back;
}
/** Allocate memory for a new record.
+
@param ks
@param vs
@param erp
@@ -192,13 +184,17 @@ dk4dbi_datum_new(
dk4_dbi_datum_t *back = NULL;
-#line 691 "dk4dbi.ctr"
+#line 725 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(0 < ks);
+ assert(0 < vs);
+#endif
back = dk4mem_new(dk4_dbi_datum_t,1,erp);
if (NULL != back) {
back->kd = back->vd = NULL;
back->ks = back->vs = (size_t)0UL;
- back->kd = dk4mem_new(char,ks,erp);
- back->vd = dk4mem_new(char,vs,erp);
+ if (0 < ks) { back->kd = dk4mem_new(char,ks,erp); }
+ if (0 < vs) { back->vd = dk4mem_new(char,vs,erp); }
if ((NULL != back->kd) && (NULL != back->vd)) {
back->ks = ks; back->vs = vs;
} else {
@@ -209,7 +205,7 @@ dk4dbi_datum_new(
}
}
-#line 706 "dk4dbi.ctr"
+#line 744 "dk4dbi.ctr"
return back;
}
@@ -250,19 +246,22 @@ dk4dbi_mem_to_file(
-#line 745 "dk4dbi.ctr"
+#line 783 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (dk4isadmin()) { tests = DK4_FOPEN_SC_PRIVILEGED; }
fipo = dk4fopen(db->fn, dkT("wb"), tests, erp);
if (NULL != fipo) {
-#line 748 "dk4dbi.ctr"
+#line 789 "dk4dbi.ctr"
back = 1;
dk4sto_it_reset((db->dt).mem.i);
do {
rp = (dk4_dbi_datum_t *)dk4sto_it_next((db->dt).mem.i);
if (NULL != rp) {
-#line 753 "dk4dbi.ctr"
+#line 794 "dk4dbi.ctr"
uc[0] = (unsigned char)(((unsigned long)(rp->ks) >> 24) & 0x000000FFUL);
uc[1] = (unsigned char)(((unsigned long)(rp->ks) >> 16) & 0x000000FFUL);
uc[2] = (unsigned char)(((unsigned long)(rp->ks) >> 8) & 0x000000FFUL);
@@ -274,30 +273,30 @@ dk4dbi_mem_to_file(
nbw = fwrite(uc, 1, 8, fipo);
if (8 == nbw) {
-#line 763 "dk4dbi.ctr"
+#line 804 "dk4dbi.ctr"
nbw = fwrite(rp->kd, 1, rp->ks, fipo);
if (rp->ks == nbw) {
-#line 765 "dk4dbi.ctr"
+#line 806 "dk4dbi.ctr"
nbw = fwrite(rp->vd, 1, rp->vs, fipo);
if (rp->vs == nbw) {
-#line 767 "dk4dbi.ctr"
+#line 808 "dk4dbi.ctr"
} else {
back = 0;
-#line 769 "dk4dbi.ctr"
+#line 810 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_WRITE_FAILED);
}
} else {
-#line 772 "dk4dbi.ctr"
+#line 813 "dk4dbi.ctr"
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_WRITE_FAILED);
}
} else {
-#line 776 "dk4dbi.ctr"
+#line 817 "dk4dbi.ctr"
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_WRITE_FAILED);
}
@@ -305,20 +304,20 @@ dk4dbi_mem_to_file(
} while (NULL != rp);
if (0 != fclose(fipo)) {
-#line 782 "dk4dbi.ctr"
+#line 823 "dk4dbi.ctr"
back = 0;
dk4error_set_idetails(erp, DK4_E_CLOSE_FAILED, errno);
}
} else {
-#line 786 "dk4dbi.ctr"
+#line 827 "dk4dbi.ctr"
}
if (0 != back) {
db->uc = 0;
}
-#line 791 "dk4dbi.ctr"
+#line 832 "dk4dbi.ctr"
return back;
}
@@ -364,7 +363,10 @@ dk4dbi_mem_from_file(
int cc = 1; /* Flag: Can continue */
-#line 835 "dk4dbi.ctr"
+#line 876 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
fipo = dk4fopen(db->fn, dkT("rb"), 0, erp);
if (NULL != fipo) {
back = 1;
@@ -372,7 +374,7 @@ dk4dbi_mem_from_file(
nbr = fread(uc, 1, 8, fipo);
if (8 == nbr) {
-#line 841 "dk4dbi.ctr"
+#line 885 "dk4dbi.ctr"
ul1 = ((((unsigned long)(uc[0])) << 24) & 0xFF000000UL)
| ((((unsigned long)(uc[1])) << 16) & 0x00FF0000UL)
| ((((unsigned long)(uc[2])) << 8) & 0x0000FF00UL)
@@ -381,8 +383,14 @@ dk4dbi_mem_from_file(
| ((((unsigned long)(uc[5])) << 16) & 0x00FF0000UL)
| ((((unsigned long)(uc[6])) << 8) & 0x0000FF00UL)
| ((((unsigned long)(uc[7])) ) & 0x000000FFUL);
- if ((dk4_um_t)(SIZE_MAX) >= (dk4_um_t)ul1) {
- if ((dk4_um_t)(SIZE_MAX) >= (dk4_um_t)ul2) {
+#if 0
+ if ((dk4_um_t)(SIZE_MAX) >= (dk4_um_t)ul1)
+#endif
+ if (0 != dk4ma_um_isgeq(SIZE_MAX, ul1)) {
+#if 0
+ if ((dk4_um_t)(SIZE_MAX) >= (dk4_um_t)ul2)
+#endif
+ if (0 != dk4ma_um_isgeq(SIZE_MAX, ul2)) {
ks = (size_t)ul1; vs = (size_t)ul2;
if (
(((size_t)0UL == db->km) || (db->km >= ks))
@@ -393,7 +401,7 @@ dk4dbi_mem_from_file(
rp = dk4dbi_datum_new(ks, vs, erp);
if (NULL != rp) {
-#line 860 "dk4dbi.ctr"
+#line 910 "dk4dbi.ctr"
nbr = fread(rp->kd, 1, rp->ks, fipo);
if (nbr == rp->ks) {
nbr = fread(rp->vd, 1, rp->vs, fipo);
@@ -401,13 +409,13 @@ dk4dbi_mem_from_file(
if (0 == dk4sto_add((db->dt).mem.s, rp, erp)) {
cc = 0;
-#line 866 "dk4dbi.ctr"
+#line 916 "dk4dbi.ctr"
back = 0;
dk4dbi_datum_delete(rp, 0);
}
} else {
-#line 870 "dk4dbi.ctr"
+#line 920 "dk4dbi.ctr"
cc = 0;
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
@@ -415,7 +423,7 @@ dk4dbi_mem_from_file(
}
} else {
-#line 876 "dk4dbi.ctr"
+#line 926 "dk4dbi.ctr"
cc = 0;
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
@@ -423,7 +431,7 @@ dk4dbi_mem_from_file(
}
} else {
-#line 882 "dk4dbi.ctr"
+#line 932 "dk4dbi.ctr"
cc = 0;
back = 0;
}
@@ -431,28 +439,28 @@ dk4dbi_mem_from_file(
else
{
-#line 888 "dk4dbi.ctr"
+#line 938 "dk4dbi.ctr"
cc = 0;
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
}
} else {
-#line 893 "dk4dbi.ctr"
+#line 943 "dk4dbi.ctr"
cc = 0;
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
}
} else {
-#line 898 "dk4dbi.ctr"
+#line 948 "dk4dbi.ctr"
cc = 0;
back = 0;
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
}
} else {
-#line 903 "dk4dbi.ctr"
+#line 953 "dk4dbi.ctr"
cc = 0;
if (0 != nbr) {
back = 0;
@@ -463,16 +471,16 @@ dk4dbi_mem_from_file(
(void)fclose(fipo);
} else {
-#line 912 "dk4dbi.ctr"
+#line 962 "dk4dbi.ctr"
if (0 == dk4stat(&stb, db->fn, NULL)) {
back = 1;
-#line 914 "dk4dbi.ctr"
+#line 964 "dk4dbi.ctr"
}
}
-#line 917 "dk4dbi.ctr"
+#line 967 "dk4dbi.ctr"
return back;
}
@@ -486,14 +494,15 @@ dk4dbi_mem_from_file(
*/
static
int
-dk4dbi_datum_compare(const void *l, const void *r, int cr)
+dk4dbi_datum_compare(const void *l, const void *r, int DK4_ARG_UNUSED(cr) )
{
dk4_dbi_datum_t *pl; /* Left pointer */
dk4_dbi_datum_t *pr; /* Right pointer */
int back = 0;
-#line 936 "dk4dbi.ctr"
+#line 986 "dk4dbi.ctr"
+ DK4_UNUSED_ARG(cr)
if (NULL != l) {
if (NULL != r) {
pl = (dk4_dbi_datum_t *)l;
@@ -527,7 +536,7 @@ dk4dbi_datum_compare(const void *l, const void *r, int cr)
}
-#line 968 "dk4dbi.ctr"
+#line 1019 "dk4dbi.ctr"
return back;
}
@@ -542,14 +551,17 @@ dk4dbi_delete_base(dk4_dbi_t *ptr)
{
-#line 981 "dk4dbi.ctr"
+#line 1032 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != ptr);
+#endif
if (NULL != ptr) {
dk4mem_release(ptr->fn);
dk4mem_free(ptr);
}
-#line 986 "dk4dbi.ctr"
+#line 1040 "dk4dbi.ctr"
}
@@ -558,6 +570,8 @@ dk4dbi_delete_base(dk4_dbi_t *ptr)
@param fn File name.
@param tp Backend type.
@param wa Flag: Write access required.
+ @param km
+ @param vm
@param erp Error report, may be NULL.
@return Pointer to memory on success, NULL on error.
@@ -582,7 +596,11 @@ dk4dbi_new_base(
dk4_dbi_t *back = NULL;
-#line 1017 "dk4dbi.ctr"
+#line 1073 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+ assert((DK4_DB_BE_MEMORY == tp) || (DK4_DB_BE_BDB == tp) || (DK4_DB_BE_NDBM == tp));
+#endif
back = dk4mem_new(dk4_dbi_t,1,erp);
if (NULL != back) {
back->tp = tp;
@@ -610,14 +628,14 @@ dk4dbi_new_base(
back->fn = dk4str_dup(fn, erp);
if (NULL == back->fn) {
-#line 1043 "dk4dbi.ctr"
+#line 1103 "dk4dbi.ctr"
dk4mem_free(back);
back = NULL;
}
}
-#line 1048 "dk4dbi.ctr"
+#line 1108 "dk4dbi.ctr"
return back;
}
@@ -655,14 +673,17 @@ dk4dbi_close_mem(
int back = 1;
-#line 1084 "dk4dbi.ctr"
+#line 1144 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if ((NULL != (db->dt).mem.s) && (NULL != (db->dt).mem.i)) {
/*
Write records to file if there are unsaved changes.
*/
-#line 1089 "dk4dbi.ctr"
+#line 1152 "dk4dbi.ctr"
if ((0 != db->wa) && (0 != db->uc)) {
if (0 == dk4dbi_mem_to_file(db, erp)) {
back = 0;
@@ -688,7 +709,7 @@ dk4dbi_close_mem(
dk4sto_close((db->dt).mem.s);
}
-#line 1113 "dk4dbi.ctr"
+#line 1176 "dk4dbi.ctr"
return back;
}
@@ -738,7 +759,10 @@ dk4dbi_open_mem(
dk4_dbi_t *back = NULL;
-#line 1161 "dk4dbi.ctr"
+#line 1224 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+#endif
if (0 != tr) {
(void)dk4delete_file(fn, NULL);
}
@@ -770,7 +794,7 @@ dk4dbi_open_mem(
}
-#line 1191 "dk4dbi.ctr"
+#line 1257 "dk4dbi.ctr"
return back;
}
@@ -784,7 +808,6 @@ dk4dbi_open_mem(
dk4dbi_close() function calls dk4dbi_delete_base()
to release the base components.
@param db Database to close.
- @param erp Error report, may be NULL.
@return 1 on success, 0 on error.
Error codes:
@@ -803,11 +826,13 @@ dk4dbi_open_mem(
static
int
dk4dbi_close_bdb(
- dk4_dbi_t *db,
- dk4_er_t *erp
+ dk4_dbi_t *db
)
{
int back = 1;
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != (db->dt).bdb.db) {
if ((0 != db->wa) && (0 != db->uc)) {
if (0 != ((db->dt).bdb.db)->sync((db->dt).bdb.db, 0)) {
@@ -870,7 +895,10 @@ dk4dbi_open_bdb(
int flags = 0;
-#line 1289 "dk4dbi.ctr"
+#line 1356 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+#endif
back = dk4dbi_new_base(fn, DK4_DB_BE_BDB, wa, km, vm, erp);
if (NULL != back) {
if (0 != tr) {
@@ -880,7 +908,7 @@ dk4dbi_open_bdb(
if (0 == res) {
((back->dt).bdb.db)->set_errfile((back->dt).bdb.db, NULL);
flags = ((0 != wa)
- ? ((0 != tr) ? ((DB_CREATE) || (DB_TRUNCATE)) : (DB_CREATE))
+ ? ((0 != tr) ? ((DB_CREATE) | (DB_TRUNCATE)) : (DB_CREATE))
: (DB_RDONLY));
res = ((back->dt).bdb.db)->open(
(back->dt).bdb.db, NULL, back->fn, NULL, DB_BTREE, flags, 0600
@@ -907,7 +935,7 @@ dk4dbi_open_bdb(
}
-#line 1324 "dk4dbi.ctr"
+#line 1394 "dk4dbi.ctr"
return back;
#endif
}
@@ -950,6 +978,9 @@ dk4dbi_close_ndbm(
)
{
int back = 1;
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != (db->dt).ndbm.dbm) {
dbm_close((db->dt).ndbm.dbm);
(db->dt).ndbm.dbm = NULL;
@@ -965,7 +996,9 @@ dk4dbi_truncate_ndbm(const dkChar *fn)
{
dkChar buf[DK4_MAX_PATH];
const size_t szbuf = DK4_SIZEOF(buf,dkChar);
-
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+#endif
if (0 != dk4str_cpy_s(buf, szbuf, fn, NULL)) {
if (0 != dk4str_cat_s(buf, szbuf, dk4dbi_ndbm_suffixes[0], NULL)) {
(void)dk4delete_file(buf, NULL);
@@ -1005,8 +1038,10 @@ dk4dbi_open_ndbm(
-#line 1420 "dk4dbi.ctr"
-
+#line 1495 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+#endif
if (0 != tr) {
dk4dbi_truncate_ndbm(fn);
}
@@ -1028,7 +1063,7 @@ dk4dbi_open_ndbm(
}
-#line 1441 "dk4dbi.ctr"
+#line 1518 "dk4dbi.ctr"
return back;
}
@@ -1051,7 +1086,11 @@ dk4dbi_open_with_type(
dk4_dbi_t *back = NULL;
-#line 1462 "dk4dbi.ctr"
+#line 1539 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+ assert((DK4_DB_BE_MEMORY == tp) || (DK4_DB_BE_BDB == tp) || (DK4_DB_BE_NDBM == tp));
+#endif
if (NULL != fn) {
switch (tp) {
case DK4_DB_BE_MEMORY : {
@@ -1080,7 +1119,7 @@ dk4dbi_open_with_type(
}
-#line 1489 "dk4dbi.ctr"
+#line 1570 "dk4dbi.ctr"
return back;
}
@@ -1104,7 +1143,10 @@ dk4dbi_open(
-#line 1511 "dk4dbi.ctr"
+#line 1592 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != fn);
+#endif
if (NULL != fn) {
mycopy = dk4str_dup(fn, erp);
if (NULL != mycopy) {
@@ -1136,7 +1178,7 @@ dk4dbi_open(
}
-#line 1541 "dk4dbi.ctr"
+#line 1625 "dk4dbi.ctr"
return back;
}
@@ -1146,6 +1188,9 @@ const dkChar *
dk4dbi_filename_part(const dkChar *filename)
{
const dkChar *back = NULL;
+#if DK4_USE_ASSERT
+ assert(NULL != filename);
+#endif
if (NULL != filename) {
back = dk4str_chr(filename, dkT(':'));
if (NULL != back) {
@@ -1173,7 +1218,10 @@ dk4dbi_close(
int back = 0;
-#line 1576 "dk4dbi.ctr"
+#line 1663 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
switch (db->tp) {
case DK4_DB_BE_MEMORY : {
@@ -1181,7 +1229,7 @@ dk4dbi_close(
} break;
case DK4_DB_BE_BDB : {
#if DK4_HAVE_DB_H && (DK4_CHAR_SIZE == 1)
- back = dk4dbi_close_bdb(db, erp);
+ back = dk4dbi_close_bdb(db);
#else
dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
#endif
@@ -1200,7 +1248,7 @@ dk4dbi_close(
}
-#line 1601 "dk4dbi.ctr"
+#line 1691 "dk4dbi.ctr"
return back;
}
@@ -1214,6 +1262,10 @@ dk4dbi_set_option(
)
{
int back = 0;
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+ assert((DK4_DB_OPT_RESET_KEY == opt) || (DK4_DB_OPT_RESET_VALUE == opt));
+#endif
if (NULL != db) {
switch (opt) {
case DK4_DB_OPT_RESET_KEY :
@@ -1253,7 +1305,11 @@ dk4dbi_delete(
-#line 1652 "dk4dbi.ctr"
+#line 1746 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+ assert(0 != db->wa);
+#endif
if ((NULL != db) && (NULL != kp) && ((size_t)0UL < ks)) {
if ((0 != db->wa) && (((size_t)0UL == db->km) || (db->km >= ks))) {
switch (db->tp) {
@@ -1321,7 +1377,7 @@ dk4dbi_delete(
}
-#line 1718 "dk4dbi.ctr"
+#line 1816 "dk4dbi.ctr"
return back;
}
@@ -1352,13 +1408,17 @@ dk4dbi_set(
-#line 1747 "dk4dbi.ctr"
+#line 1845 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+ assert(0 != db->wa);
+#endif
if ((NULL != db) && (NULL != kp) && ((size_t)0UL < ks)) {
-#line 1748 "dk4dbi.ctr"
+#line 1850 "dk4dbi.ctr"
if ((NULL != vp) && ((size_t)0UL < vs)) {
-#line 1749 "dk4dbi.ctr"
+#line 1851 "dk4dbi.ctr"
if(
(((size_t)0UL == db->km) || (db->km >= ks))
&& (((size_t)0UL == db->vm) || (db->vm >= vs))
@@ -1366,11 +1426,11 @@ dk4dbi_set(
)
{
-#line 1755 "dk4dbi.ctr"
+#line 1857 "dk4dbi.ctr"
switch (db->tp) {
case DK4_DB_BE_MEMORY : {
-#line 1757 "dk4dbi.ctr"
+#line 1859 "dk4dbi.ctr"
db->uc = 1;
dat.kd = (void *)kp; dat.ks = ks;
rp = (dk4_dbi_datum_t *)dk4sto_it_find_like(
@@ -1407,14 +1467,14 @@ dk4dbi_set(
} break;
case DK4_DB_BE_BDB : {
-#line 1792 "dk4dbi.ctr"
+#line 1894 "dk4dbi.ctr"
#if DK4_HAVE_DB_H && (DK4_CHAR_SIZE == 1)
-#line 1794 "dk4dbi.ctr"
+#line 1896 "dk4dbi.ctr"
if (NULL != (db->dt).bdb.db) {
-#line 1795 "dk4dbi.ctr"
+#line 1897 "dk4dbi.ctr"
db->uc = 1;
DK4_MEMRES(&k, sizeof(DBT));
DK4_MEMRES(&v, sizeof(DBT));
@@ -1422,25 +1482,25 @@ dk4dbi_set(
k.size = ks; v.size = vs;
-#line 1801 "dk4dbi.ctr"
+#line 1903 "dk4dbi.ctr"
((db->dt).bdb.db)->del((db->dt).bdb.db, NULL, &k, 0);
DK4_MEMRES(&k, sizeof(DBT));
k.data = (void *)kp; k.size = ks;
-#line 1805 "dk4dbi.ctr"
+#line 1907 "dk4dbi.ctr"
if (0 == ((db->dt).bdb.db)->put((db->dt).bdb.db,NULL,&k,&v,0)) {
back = 1;
-#line 1807 "dk4dbi.ctr"
+#line 1909 "dk4dbi.ctr"
} else {
-#line 1808 "dk4dbi.ctr"
+#line 1910 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_WRITE_FAILED);
}
} else {
-#line 1811 "dk4dbi.ctr"
+#line 1913 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
#else
@@ -1449,7 +1509,7 @@ dk4dbi_set(
} break;
case DK4_DB_BE_NDBM : {
-#line 1818 "dk4dbi.ctr"
+#line 1920 "dk4dbi.ctr"
#if DK4_HAVE_NDBM_H && (DK4_CHAR_SIZE == 1)
if (NULL != (db->dt).ndbm.dbm) {
db->uc = 1;
@@ -1482,22 +1542,22 @@ dk4dbi_set(
else
{
-#line 1849 "dk4dbi.ctr"
+#line 1951 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
}
} else {
-#line 1852 "dk4dbi.ctr"
+#line 1954 "dk4dbi.ctr"
back = dk4dbi_delete(db, kp, ks, erp);
}
} else {
-#line 1855 "dk4dbi.ctr"
+#line 1957 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
-#line 1858 "dk4dbi.ctr"
+#line 1960 "dk4dbi.ctr"
return back;
}
@@ -1512,7 +1572,10 @@ dk4dbi_sync(
int back = 0;
-#line 1871 "dk4dbi.ctr"
+#line 1973 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
switch (db->tp) {
case DK4_DB_BE_MEMORY : {
@@ -1559,7 +1622,7 @@ dk4dbi_sync(
}
-#line 1916 "dk4dbi.ctr"
+#line 2021 "dk4dbi.ctr"
return back;
}
@@ -1589,7 +1652,12 @@ dk4dbi_get(
-#line 1944 "dk4dbi.ctr"
+#line 2049 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+ assert(NULL != vp);
+ assert(NULL != vs);
+#endif
if (
(NULL != db) && (NULL != kp) && ((size_t)0 < ks)
&& (NULL != vp) && (NULL != vs)
@@ -1600,7 +1668,7 @@ dk4dbi_get(
switch (db->tp) {
case DK4_DB_BE_MEMORY : {
-#line 1953 "dk4dbi.ctr"
+#line 2063 "dk4dbi.ctr"
dat.kd = (void *)kp; dat.ks = ks;
rp = (dk4_dbi_datum_t *)dk4sto_it_find_like(
(db->dt).mem.i, &dat, 0
@@ -1623,14 +1691,14 @@ dk4dbi_get(
} break;
case DK4_DB_BE_BDB : {
-#line 1974 "dk4dbi.ctr"
+#line 2084 "dk4dbi.ctr"
#if DK4_HAVE_DB_H && (DK4_CHAR_SIZE == 1)
-#line 1976 "dk4dbi.ctr"
+#line 2086 "dk4dbi.ctr"
if (NULL != (db->dt).bdb.db) {
-#line 1977 "dk4dbi.ctr"
+#line 2087 "dk4dbi.ctr"
DK4_MEMRES(&k, sizeof(DBT));
DK4_MEMRES(&v, sizeof(DBT));
k.data = (void *)kp; k.size = ks;
@@ -1638,28 +1706,28 @@ dk4dbi_get(
if (0 == ((db->dt).bdb.db)->get((db->dt).bdb.db,NULL,&k,&v,0)) {
*vs = v.size;
-#line 1983 "dk4dbi.ctr"
+#line 2093 "dk4dbi.ctr"
back = 1;
} else {
-#line 1985 "dk4dbi.ctr"
+#line 2095 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
}
} else {
-#line 1988 "dk4dbi.ctr"
+#line 2098 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
#else
-#line 1992 "dk4dbi.ctr"
+#line 2102 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
#endif
} break;
case DK4_DB_BE_NDBM : {
-#line 1996 "dk4dbi.ctr"
+#line 2106 "dk4dbi.ctr"
#if DK4_HAVE_NDBM_H && (DK4_CHAR_SIZE == 1)
if (NULL != (db->dt).ndbm.dbm) {
DK4_MEMRES(&datk, sizeof(datum));
@@ -1687,22 +1755,22 @@ dk4dbi_get(
}
} else {
-#line 2022 "dk4dbi.ctr"
+#line 2132 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
} else {
-#line 2025 "dk4dbi.ctr"
+#line 2135 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
} else {
-#line 2028 "dk4dbi.ctr"
+#line 2138 "dk4dbi.ctr"
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
-#line 2031 "dk4dbi.ctr"
+#line 2141 "dk4dbi.ctr"
return back;
}
@@ -1726,19 +1794,25 @@ dk4dbi_traverse(
#endif
dk4_dbi_datum_t *dddt = NULL; /* Pointer for traversal */
int res = 0; /* Operation result */
+#if (DK4_CHAR_SIZE == 1) && ((DK4_HAVE_NDBM_H) || (DK4_HAVE_DB_H))
int first = 1; /* Flag: Retrieving first record */
+#endif
int back = -1;
-#line 2058 "dk4dbi.ctr"
+#line 2170 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+ assert(NULL != fct);
+#endif
if ((NULL != db) && (NULL != fct)) {
switch (db->tp) {
case DK4_DB_BE_MEMORY : {
back = 1;
dk4sto_it_reset((db->dt).mem.i);
do {
- dddt = dk4sto_it_next((db->dt).mem.i);
+ dddt = (dk4_dbi_datum_t *)dk4sto_it_next((db->dt).mem.i);
if (NULL != dddt) {
res = (*fct)(obj, dddt->kd, dddt->ks, dddt->vd, dddt->vs);
if (res < back) { back = res; }
@@ -1774,11 +1848,11 @@ dk4dbi_traverse(
cp->c_close(cp);
} else {
-#line 2099 "dk4dbi.ctr"
+#line 2215 "dk4dbi.ctr"
}
} else {
-#line 2101 "dk4dbi.ctr"
+#line 2217 "dk4dbi.ctr"
}
#endif
} break;
@@ -1809,7 +1883,7 @@ dk4dbi_traverse(
}
}
-#line 2130 "dk4dbi.ctr"
+#line 2246 "dk4dbi.ctr"
return back;
}
@@ -1847,7 +1921,7 @@ dk4dbi_change_file_owner_and_mode(
-#line 2166 "dk4dbi.ctr"
+#line 2282 "dk4dbi.ctr"
errno = 0;
if (0 == chown(fn, user, group)) {
errno = 0;
@@ -1860,7 +1934,7 @@ dk4dbi_change_file_owner_and_mode(
dk4error_set_idetails(erp, DK4_E_SYSTEM, errno);
}
-#line 2177 "dk4dbi.ctr"
+#line 2293 "dk4dbi.ctr"
return back;
}
@@ -1880,7 +1954,10 @@ dk4dbi_change_owner_and_mode(
-#line 2195 "dk4dbi.ctr"
+#line 2311 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
switch (db->tp) {
case DK4_DB_BE_MEMORY :
@@ -1914,7 +1991,7 @@ dk4dbi_change_owner_and_mode(
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
-#line 2227 "dk4dbi.ctr"
+#line 2346 "dk4dbi.ctr"
return back;
}
@@ -1936,14 +2013,17 @@ dk4dbi_get_key_max(
size_t back = 0;
-#line 2247 "dk4dbi.ctr"
+#line 2366 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
back = db->km;
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
-#line 2252 "dk4dbi.ctr"
+#line 2374 "dk4dbi.ctr"
return back;
}
@@ -1958,14 +2038,17 @@ dk4dbi_get_val_max(
size_t back = 0;
-#line 2265 "dk4dbi.ctr"
+#line 2387 "dk4dbi.ctr"
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
back = db->vm;
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
-#line 2270 "dk4dbi.ctr"
+#line 2395 "dk4dbi.ctr"
return back;
}
@@ -1975,6 +2058,9 @@ int
dk4dbi_get_type(const dk4_dbi_t *db)
{
int back = DK4_DB_BE_UNKNOWN;
+#if DK4_USE_ASSERT
+ assert(NULL != db);
+#endif
if (NULL != db) {
back = db->tp;
}