AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
+
+dnl Determine the size of datum and DBT size fields. If they are not the same
+dnl then the elements need to be copied.
+AC_MSG_CHECKING(size of datum.dsize)
+AC_CACHE_VAL(ac_cv_sizeof_datum_dsize,
+[AC_TRY_RUN([#include <stdio.h>
+#include <ndbm.h>
+main()
+{
+ FILE *f=fopen("conftestval", "w");
+ datum k;
+ if (!f) exit(1);
+ fprintf(f, "%d\n", sizeof(k.dsize));
+ exit(0);
+}], ac_cv_sizeof_datum_dsize=`cat conftestval`)])dnl
+AC_MSG_RESULT($ac_cv_sizeof_datum_dsize)
+AC_DEFINE_UNQUOTED(SIZEOF_DATUM_DSIZE, $ac_cv_sizeof_datum_dsize)
+
+AC_MSG_CHECKING(size of DBT.size)
+AC_CACHE_VAL(ac_cv_sizeof_dbt_size,
+[AC_TRY_RUN([#include <stdio.h>
+#include <sys/types.h>
+typedef struct {
+ void *data; /* data */
+ size_t size; /* data length */
+} DBT;
+main()
+{
+ FILE *f=fopen("conftestval", "w");
+ DBT k;
+ if (!f) exit(1);
+ fprintf(f, "%d\n", sizeof(k.size));
+ exit(0);
+}], ac_cv_sizeof_dbt_size=`cat conftestval`)])dnl
+AC_MSG_RESULT($ac_cv_sizeof_dbt_size)
+AC_DEFINE_UNQUOTED(SIZEOF_DBT_SIZE, $ac_cv_sizeof_dbt_size)
+
AC_HAVE_FUNCS(mktemp mkstemp)
CHECK_SIGNALS
SubdirLibraryRule([$(OBJS)])
#include <ndbm.h>
#include "hash.h"
+/* If the two size fields are not equal, then casting between structures will
+ result in stack garbage being transfered. Has been observed for DEC Alpha
+ OSF, but will handle the general case.
+*/
+
+#ifndef SIZEOF_DBT_SIZE
+#define SIZEOF_DBT_SIZE 4
+#endif
+#ifndef SIZEOF_DATUM_DSIZE
+#define SIZEOF_DATUM_DSIZE 4
+#endif
+
+#if SIZEOF_DBT_SIZE != SIZEOF_DATUM_DSIZE
+#define NEED_COPY
+#endif
+
/*
* For Kerberos, we make some generalizations about kdb records. We assume
* that records are on average KRB5_DBENT_ASIZE in length.
{
datum retval;
int status;
+#ifdef NEED_COPY
+ DBT k, r;
+ k.data = key.dptr;
+ k.size = key.dsize;
+ status = (db->get)(db, &k, &r, 0);
+ retval.dptr = r.data;
+ retval.dsize = r.size;
+#else
status = (db->get)(db, (DBT *)&key, (DBT *)&retval, 0);
+#endif
if (status) {
retval.dptr = NULL;
retval.dsize = 0;
{
int status;
datum retdata, retkey;
+#ifdef NEED_COPY
+ DBT k, r;
+ status = (db->seq)(db, &k, &r, R_FIRST);
+ retkey.dptr = k.data;
+ retkey.dsize = k.size;
+#else
status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST);
+#endif
if (status)
retkey.dptr = NULL;
return (retkey);
{
int status;
datum retdata, retkey;
+#ifdef NEED_COPY
+ DBT k, r;
+ status = (db->seq)(db, &k, &r, R_NEXT);
+ retkey.dptr = k.data;
+ retkey.dsize = k.size;
+#else
status = (db->seq)(db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT);
+#endif
if (status)
retkey.dptr = NULL;
return (retkey);
datum key;
{
int status;
+#ifdef NEED_COPY
+ DBT k;
+
+ k.data = key.dptr;
+ k.size = key.dsize;
+ status = (db->del)(db, &k, 0);
+#else
status = (db->del)(db, (DBT *)&key, 0);
+#endif
if (status)
return (-1);
else
datum key, content;
int flags;
{
+#ifdef NEED_COPY
+ DBT k, c;
+
+ k.data = key.dptr;
+ k.size = key.dsize;
+ c.data = content.dptr;
+ c.size = content.dsize;
+ return ((db->put)(db, &k, &c,
+ (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
+#else
return ((db->put)(db, (DBT *)&key, (DBT *)&content,
(flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
+#endif
}
extern int