Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Functions
rec_seq.c File Reference
#include <sys/types.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "../include/db.h"
#include "recno.h"
Include dependency graph for rec_seq.c:

Go to the source code of this file.

Functions

int __rec_seq (DB *dbp, DBT *key, DBT *data, u_int flags) const
 

Function Documentation

◆ __rec_seq()

int __rec_seq ( DB dbp,
DBT key,
DBT data,
u_int  flags 
) const

Definition at line 61 of file rec_seq.c.

65 {
66  BTREE *t;
67  EPG *e;
68  recno_t nrec;
69  int status;
70 
71  t = dbp->internal;
72 
73  /* Toss any page pinned across calls. */
74  if (t->bt_pinned != NULL) {
75  mpool_put(t->bt_mp, t->bt_pinned, 0);
76  t->bt_pinned = NULL;
77  }
78 
79  switch(flags) {
80  case R_CURSOR:
81  if ((nrec = *(recno_t *)key->data) == 0)
82  goto einval;
83  break;
84  case R_NEXT:
85  if (F_ISSET(&t->bt_cursor, CURS_INIT)) {
86  nrec = t->bt_cursor.rcursor + 1;
87  break;
88  }
89  /* FALLTHROUGH */
90  case R_FIRST:
91  nrec = 1;
92  break;
93  case R_PREV:
94  if (F_ISSET(&t->bt_cursor, CURS_INIT)) {
95  if ((nrec = t->bt_cursor.rcursor - 1) == 0)
96  return (RET_SPECIAL);
97  break;
98  }
99  /* FALLTHROUGH */
100  case R_LAST:
101  if (!F_ISSET(t, R_EOF | R_INMEM) &&
102  t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR)
103  return (RET_ERROR);
104  nrec = t->bt_nrecs;
105  break;
106  default:
107 einval: errno = EINVAL;
108  return (RET_ERROR);
109  }
110 
111  if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) {
112  if (!F_ISSET(t, R_EOF | R_INMEM) &&
113  (status = t->bt_irec(t, nrec)) != RET_SUCCESS)
114  return (status);
115  if (t->bt_nrecs == 0 || nrec > t->bt_nrecs)
116  return (RET_SPECIAL);
117  }
118 
119  if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL)
120  return (RET_ERROR);
121 
122  F_SET(&t->bt_cursor, CURS_INIT);
123  t->bt_cursor.rcursor = nrec;
124 
125  status = __rec_ret(t, e, nrec, key, data);
126  if (F_ISSET(t, B_DB_LOCK))
127  mpool_put(t->bt_mp, e->page, 0);
128  else
129  t->bt_pinned = e->page;
130  return (status);
131 }
jack_status_t status
Definition: app_jack.c:146
#define F_ISSET(p, f)
Definition: btree.h:42
#define CURS_INIT
Definition: btree.h:291
#define F_SET(p, f)
Definition: btree.h:40
#define R_INMEM
Definition: btree.h:381
#define R_EOF
Definition: btree.h:378
#define B_DB_LOCK
Definition: btree.h:385
#define R_PREV
Definition: db.h:99
#define R_NEXT
Definition: db.h:97
#define R_FIRST
Definition: db.h:93
#define R_LAST
Definition: db.h:96
#define R_CURSOR
Definition: db.h:91
#define RET_SUCCESS
Definition: db.h:52
#define MAX_REC_NUMBER
Definition: db.h:81
u_int32_t recno_t
Definition: db.h:82
#define RET_ERROR
Definition: db.h:51
#define RET_SPECIAL
Definition: db.h:53
static DB * dbp
Definition: hsearch.c:49
int errno
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
EPG * __rec_search(BTREE *t, recno_t recno, enum SRCHOP op)
Definition: rec_search.c:64
int __rec_ret(BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data)
Definition: rec_utils.c:62
@ SEARCH
Definition: recno.h:36
#define NULL
Definition: resample.c:96
void * data
Definition: db.h:86
void * internal
Definition: db.h:137
Definition: btree.h:312
CURSOR bt_cursor
Definition: btree.h:320
MPOOL * bt_mp
Definition: btree.h:313
PAGE * bt_pinned
Definition: btree.h:318
recno_t bt_nrecs
Definition: btree.h:360
recno_t rcursor
Definition: btree.h:286
Definition: btree.h:254
PAGE * page
Definition: btree.h:255

References __rec_ret(), __rec_search(), B_DB_LOCK, _btree::bt_cursor, _btree::bt_mp, _btree::bt_nrecs, _btree::bt_pinned, CURS_INIT, DBT::data, dbp, errno, F_ISSET, F_SET, __db::internal, MAX_REC_NUMBER, mpool_put(), NULL, _epg::page, R_CURSOR, R_EOF, R_FIRST, R_INMEM, R_LAST, R_NEXT, R_PREV, _cursor::rcursor, RET_ERROR, RET_SPECIAL, RET_SUCCESS, SEARCH, and status.

Referenced by __rec_open().