Back to index

php5  5.3.10
Defines | Functions
cdb.c File Reference
#include "php.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>
#include "cdb.h"

Go to the source code of this file.

Defines

#define EPROTO   -15 /* cdb 0.75's default for PROTOless systems */

Functions

static int cdb_match (struct cdb *c, char *key, unsigned int len, uint32 pos TSRMLS_DC)
uint32 cdb_hash (char *buf, unsigned int len)
void cdb_free (struct cdb *c TSRMLS_DC)
void cdb_findstart (struct cdb *c TSRMLS_DC)
void cdb_init (struct cdb *c, php_stream *fp TSRMLS_DC)
int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC)
int cdb_findnext (struct cdb *c, char *key, unsigned int len TSRMLS_DC)
int cdb_find (struct cdb *c, char *key, unsigned int len TSRMLS_DC)
char * cdb_version ()

Define Documentation

#define EPROTO   -15 /* cdb 0.75's default for PROTOless systems */

Definition at line 42 of file cdb.c.


Function Documentation

int cdb_find ( struct cdb c,
char *  key,
unsigned int len  TSRMLS_DC 
)

Definition at line 182 of file cdb.c.

{
       cdb_findstart(c TSRMLS_CC);
       return cdb_findnext(c, key, len TSRMLS_CC);
}

Here is the call graph for this function:

int cdb_findnext ( struct cdb c,
char *  key,
unsigned int len  TSRMLS_DC 
)

Definition at line 129 of file cdb.c.

{
       char buf[8];
       uint32 pos;
       uint32 u;

       if (!c->loop) {
              u = cdb_hash(key, len);
              if (cdb_read(c, buf, 8, (u << 3) & 2047 TSRMLS_CC) == -1) 
                     return -1;
              uint32_unpack(buf + 4,&c->hslots);
              if (!c->hslots) 
                     return 0;
              uint32_unpack(buf, &c->hpos);
              c->khash = u;
              u >>= 8;
              u %= c->hslots;
              u <<= 3;
              c->kpos = c->hpos + u;
       }

       while (c->loop < c->hslots) {
              if (cdb_read(c, buf, 8, c->kpos TSRMLS_CC) == -1) 
                     return -1;
              uint32_unpack(buf + 4, &pos);
              if (!pos) 
                     return 0;
              c->loop += 1;
              c->kpos += 8;
              if (c->kpos == c->hpos + (c->hslots << 3)) 
                     c->kpos = c->hpos;
              uint32_unpack(buf, &u);
              if (u == c->khash) {
                     if (cdb_read(c, buf, 8, pos TSRMLS_CC) == -1) 
                            return -1;
                     uint32_unpack(buf, &u);
                     if (u == len)
                     switch(cdb_match(c, key, len, pos + 8 TSRMLS_CC)) {
                     case -1:
                            return -1;
                     case 1:
                            uint32_unpack(buf + 4, &c->dlen);
                            c->dpos = pos + 8 + len;
                            return 1;
                     }
              }
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cdb_findstart ( struct cdb *c  TSRMLS_DC)

Definition at line 88 of file cdb.c.

{
       c->loop = 0;
}

Here is the caller graph for this function:

void cdb_free ( struct cdb *c  TSRMLS_DC)

Definition at line 82 of file cdb.c.

{
}

Here is the caller graph for this function:

uint32 cdb_hash ( char *  buf,
unsigned int  len 
)

Definition at line 68 of file cdb.c.

{
       uint32 h;
       const unsigned char * b = (unsigned char *)buf;

       h = CDB_HASHSTART;
       while (len--) {
              h = ( h + (h << 5)) ^ (*b++);
       }
       return h;
}

Here is the caller graph for this function:

void cdb_init ( struct cdb c,
php_stream *fp  TSRMLS_DC 
)

Definition at line 95 of file cdb.c.

Here is the call graph for this function:

static int cdb_match ( struct cdb c,
char *  key,
unsigned int  len,
uint32 pos  TSRMLS_DC 
) [static]

Definition at line 46 of file cdb.c.

{
       char buf[32];
       unsigned int n;

       while (len > 0) {
              n = sizeof(buf);
              if (n > len) 
                     n = len;
              if (cdb_read(c, buf, n, pos TSRMLS_CC) == -1) 
                     return -1;
              if (memcmp(buf, key, n)) 
                     return 0;
              pos += n;
              key += n;
              len -= n;
       }
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdb_read ( struct cdb c,
char *  buf,
unsigned int  len,
uint32 pos  TSRMLS_DC 
)

Definition at line 104 of file cdb.c.

{
       if (php_stream_seek(c->fp, pos, SEEK_SET) == -1) {
              errno = EPROTO;
              return -1;
       }
       while (len > 0) {
              int r;
              do {
                     r = php_stream_read(c->fp, buf, len);
              } while ((r == -1) && (errno == EINTR));
              if (r == -1) 
                     return -1;
              if (r == 0) {
                     errno = EPROTO;
                     return -1;
              }
              buf += r;
              len -= r;
       }
       return 0;
}

Here is the caller graph for this function:

char* cdb_version ( )

Definition at line 190 of file cdb.c.

{
       return "0.75, $Revision: 293036 $";
}