tdb2: allow multiple chain locks.
[ccan] / ccan / tdb2 / tdb.c
index 09333a26801380fb232a2fc444eb11473de8805e..18cf2e93a598ea7c3f742bcb3e445a5985686d55 100644 (file)
@@ -38,7 +38,7 @@ static enum TDB_ERROR replace_data(struct tdb_context *tdb,
 
        /* We didn't like the existing one: remove it. */
        if (old_off) {
-               add_stat(tdb, frees, 1);
+               tdb->stats.frees++;
                ecode = add_free_record(tdb, old_off,
                                        sizeof(struct tdb_used_record)
                                        + key.dsize + old_room);
@@ -285,7 +285,7 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
        }
 
        /* Free the deleted entry. */
-       add_stat(tdb, frees, 1);
+       tdb->stats.frees++;
        ecode = add_free_record(tdb, off,
                                sizeof(struct tdb_used_record)
                                + rec_key_length(&rec)
@@ -382,6 +382,11 @@ const char *tdb_errorstr(enum TDB_ERROR ecode)
        return "Invalid error code";
 }
 
+enum TDB_ERROR tdb_error(struct tdb_context *tdb)
+{
+       return tdb->last_error;
+}
+
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
                               enum TDB_ERROR ecode,
                               enum tdb_log_level level,
@@ -393,7 +398,7 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
        /* tdb_open paths care about errno, so save it. */
        int saved_errno = errno;
 
-       if (!tdb->logfn)
+       if (!tdb->log_fn)
                return ecode;
 
        va_start(ap, fmt);
@@ -401,11 +406,11 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
        va_end(ap);
 
        if (len < 0) {
-               tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_private,
-                          "out of memory formatting message:");
-               tdb->logfn(tdb, level, tdb->log_private, fmt);
+               tdb->log_fn(tdb, TDB_LOG_ERROR,
+                           "out of memory formatting message:", tdb->log_data);
+               tdb->log_fn(tdb, level, fmt, tdb->log_data);
        } else {
-               tdb->logfn(tdb, level, tdb->log_private, message);
+               tdb->log_fn(tdb, level, message, tdb->log_data);
                free(message);
        }
        errno = saved_errno;
@@ -414,10 +419,10 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
 
 enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
                                 TDB_DATA key,
-                                enum TDB_ERROR (*parse)(TDB_DATA key,
-                                                        TDB_DATA data,
-                                                        void *p),
-                                void *p)
+                                enum TDB_ERROR (*parse)(TDB_DATA k,
+                                                        TDB_DATA d,
+                                                        void *data),
+                                void *data)
 {
        tdb_off_t off;
        struct tdb_used_record rec;
@@ -438,9 +443,9 @@ enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
                if (TDB_PTR_IS_ERR(dptr)) {
                        ecode = TDB_PTR_ERR(dptr);
                } else {
-                       TDB_DATA data = tdb_mkdata(dptr, rec_data_length(&rec));
+                       TDB_DATA d = tdb_mkdata(dptr, rec_data_length(&rec));
 
-                       ecode = parse(key, data, p);
+                       ecode = parse(key, d, data);
                        tdb_access_release(tdb, dptr);
                }
        }