Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions
rec_utils.c File Reference
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/db.h"
#include "recno.h"
Include dependency graph for rec_utils.c:

Go to the source code of this file.

Functions

int __rec_ret (BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data)
 

Function Documentation

◆ __rec_ret()

int __rec_ret ( BTREE t,
EPG e,
recno_t  nrec,
DBT key,
DBT data 
)

Definition at line 62 of file rec_utils.c.

67{
68 RLEAF *rl;
69 void *p;
70
71 if (key == NULL)
72 goto dataonly;
73
74 /* We have to copy the key, it's not on the page. */
75 if (sizeof(recno_t) > t->bt_rkey.size) {
76 p = (void *)(t->bt_rkey.data == NULL ?
77 malloc(sizeof(recno_t)) :
78 realloc(t->bt_rkey.data, sizeof(recno_t)));
79 if (p == NULL)
80 return (RET_ERROR);
81 t->bt_rkey.data = p;
82 t->bt_rkey.size = sizeof(recno_t);
83 }
84 memmove(t->bt_rkey.data, &nrec, sizeof(recno_t));
85 key->size = sizeof(recno_t);
86 key->data = t->bt_rkey.data;
87
88dataonly:
89 if (data == NULL)
90 return (RET_SUCCESS);
91
92 /*
93 * We must copy big keys/data to make them contiguous. Otherwise,
94 * leave the page pinned and don't copy unless the user specified
95 * concurrent access.
96 */
97 rl = GETRLEAF(e->page, e->index);
98 if (rl->flags & P_BIGDATA) {
99 if (__ovfl_get(t, rl->bytes,
100 &data->size, &t->bt_rdata.data, &t->bt_rdata.size))
101 return (RET_ERROR);
102 data->data = t->bt_rdata.data;
103 } else if (F_ISSET(t, B_DB_LOCK)) {
104 /* Use +1 in case the first record retrieved is 0 length. */
105 if (rl->dsize + 1 > t->bt_rdata.size) {
106 p = (void *)(t->bt_rdata.data == NULL ?
107 malloc(rl->dsize + 1) :
108 realloc(t->bt_rdata.data, rl->dsize + 1));
109 if (p == NULL)
110 return (RET_ERROR);
111 t->bt_rdata.data = p;
112 t->bt_rdata.size = rl->dsize + 1;
113 }
114 memmove(t->bt_rdata.data, rl->bytes, rl->dsize);
115 data->size = rl->dsize;
116 data->data = t->bt_rdata.data;
117 } else {
118 data->size = rl->dsize;
119 data->data = rl->bytes;
120 }
121 return (RET_SUCCESS);
122}
#define realloc(a, b)
Definition: astmm.h:161
int __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz)
Definition: bt_overflow.c:80
#define F_ISSET(p, f)
Definition: btree.h:42
#define P_BIGDATA
Definition: btree.h:131
#define GETRLEAF(pg, indx)
Definition: btree.h:220
#define B_DB_LOCK
Definition: btree.h:385
#define RET_SUCCESS
Definition: db.h:52
u_int32_t recno_t
Definition: db.h:82
#define RET_ERROR
Definition: db.h:51
char * malloc()
#define NULL
Definition: resample.c:96
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
DBT bt_rkey
Definition: btree.h:332
DBT bt_rdata
Definition: btree.h:333
indx_t index
Definition: btree.h:256
PAGE * page
Definition: btree.h:255
Definition: btree.h:213
u_char flags
Definition: btree.h:215
char bytes[1]
Definition: btree.h:216
u_int32_t dsize
Definition: btree.h:214

References __ovfl_get(), B_DB_LOCK, _btree::bt_rdata, _btree::bt_rkey, _rleaf::bytes, DBT::data, _rleaf::dsize, F_ISSET, _rleaf::flags, GETRLEAF, _epg::index, malloc(), NULL, P_BIGDATA, _epg::page, realloc, RET_ERROR, RET_SUCCESS, and DBT::size.

Referenced by __rec_get(), __rec_put(), and __rec_seq().