/* Endian conversion: we only ever deal with 4 byte quantities */
void *tdb_convert(void *buf, uint32_t size)
{
- uint32_t i, *p = (uint32_t *)buf;
- for (i = 0; i < size / 4; i++)
- p[i] = TDB_BYTEREV(p[i]);
+ uint32_t i;
+ unsigned char *p = buf, tmp;
+
+ for (i = 0; i < size; i += 4) {
+ tmp = p[i];
+ p[i] = p[i+3];
+ p[i+3] = tmp;
+ tmp = p[i+1];
+ p[i+1] = p[i+2];
+ p[i+2] = tmp;
+ }
return buf;
}
#if HAVE_MMAP
if (tdb->map_ptr) {
- int ret = munmap(tdb->map_ptr, tdb->map_size);
+ int ret;
+
+ ret = munmap(tdb->map_ptr, tdb->map_size);
if (ret != 0)
return ret;
}
file and doing the mmap again if necessary */
int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
{
- struct list_struct rec;
+ struct tdb_record rec;
tdb_off_t offset, new_size;
if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
unsigned char *buf;
/* some systems don't like zero length malloc */
+
if (!(buf = (unsigned char *)malloc(len ? len : 1))) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_OOM;
}
/* read/write a record */
-int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
+int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
{
if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
return -1;
return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0);
}
-int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
+int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
{
- struct list_struct r = *rec;
+ struct tdb_record r = *rec;
return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r));
}
tdb_next_hash_chain,
tdb_oob,
tdb_expand_file,
- tdb_brlock
};
/*