2007-07-13 19:37:47 +00:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#include "ybt.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-11-29 15:17:46 +00:00
|
|
|
DBT *toku_init_dbt (DBT *ybt) {
|
2007-07-13 19:37:47 +00:00
|
|
|
memset(ybt, 0, sizeof(*ybt));
|
2007-07-24 01:32:03 +00:00
|
|
|
return ybt;
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 15:17:46 +00:00
|
|
|
DBT *toku_fill_dbt(DBT *dbt, bytevec k, ITEMLEN len) {
|
|
|
|
toku_init_dbt(dbt);
|
2007-07-23 20:10:16 +00:00
|
|
|
dbt->size=len;
|
|
|
|
dbt->data=(char*)k;
|
|
|
|
return dbt;
|
|
|
|
}
|
|
|
|
|
2007-11-29 15:17:46 +00:00
|
|
|
int toku_dbt_set_value (DBT *ybt, bytevec val, ITEMLEN vallen, void **staticptrp) {
|
2007-07-13 19:37:47 +00:00
|
|
|
if (ybt->flags==DB_DBT_MALLOC) {
|
|
|
|
domalloc:
|
2007-07-20 18:00:14 +00:00
|
|
|
ybt->data = toku_malloc(vallen);
|
2007-07-13 19:37:47 +00:00
|
|
|
if (errno!=0) return errno;
|
|
|
|
} else if (ybt->flags==DB_DBT_REALLOC) {
|
|
|
|
if (ybt->data==0) goto domalloc;
|
2007-07-20 18:00:14 +00:00
|
|
|
ybt->data = toku_realloc(ybt->data, vallen);
|
2007-07-13 19:37:47 +00:00
|
|
|
if (errno!=0) return errno;
|
|
|
|
} else if (ybt->flags==DB_DBT_USERMEM) {
|
2007-12-10 17:04:02 +00:00
|
|
|
ybt->size = vallen;
|
|
|
|
if (ybt->ulen < vallen) return DB_BUFFER_SMALL;
|
2007-07-13 19:37:47 +00:00
|
|
|
} else {
|
|
|
|
if (staticptrp==0) return -1;
|
|
|
|
void *staticptr=*staticptrp;
|
2007-07-24 03:28:48 +00:00
|
|
|
//void *old=staticptr;
|
2007-07-13 19:37:47 +00:00
|
|
|
if (staticptr==0)
|
2007-07-20 18:00:14 +00:00
|
|
|
staticptr = toku_malloc(vallen);
|
2007-07-13 19:37:47 +00:00
|
|
|
else
|
2007-07-20 18:00:14 +00:00
|
|
|
staticptr = toku_realloc(staticptr, vallen);
|
2007-07-13 19:37:47 +00:00
|
|
|
if (errno!=0) return errno;
|
2007-07-24 03:28:48 +00:00
|
|
|
//if (old!=staticptr) printf("%s:%d MALLOC --> %p\n", __FILE__, __LINE__, staticptr);
|
2007-07-13 19:37:47 +00:00
|
|
|
*staticptrp = staticptr;
|
|
|
|
ybt->data = staticptr;
|
|
|
|
}
|
|
|
|
ybt->size = vallen;
|
2007-12-10 17:04:02 +00:00
|
|
|
if (ybt->size>0) {
|
2007-07-13 19:37:47 +00:00
|
|
|
memcpy(ybt->data, val, vallen);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|