Back to index

courier  0.68.2
Functions
gdbmobj.c File Reference
#include "gdbmobj.h"
#include <stdlib.h>

Go to the source code of this file.

Functions

void gdbmobj_init (struct gdbmobj *obj)
void gdbmobj_close (struct gdbmobj *obj)
int gdbmobj_open (struct gdbmobj *obj, const char *filename, const char *modestr)
int gdbmobj_store (struct gdbmobj *obj, const char *key, size_t keylen, const char *data, size_t datalen, const char *mode)
int gdbmobj_exists (struct gdbmobj *obj, const char *key, size_t keylen)
char * gdbm_dofetch (struct gdbmobj *, const char *, size_t, size_t *)
char * gdbmobj_fetch (struct gdbmobj *obj, const char *key, size_t keylen, size_t *datalen, const char *options)

Function Documentation

char * gdbm_dofetch ( struct gdbmobj obj,
const char *  key,
size_t  keylen,
size_t *  datalen 
)

Definition at line 162 of file gdbmobj.c.

{
datum  dkey, val;

       if (!obj->has_dbf)   return (0);

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       val=gdbm_fetch(obj->dbf, dkey);

       if (!val.dptr)       return (0);
       *datalen=val.dsize;
       return (val.dptr);
}

Here is the caller graph for this function:

void gdbmobj_close ( struct gdbmobj obj)

Definition at line 27 of file gdbmobj.c.

{
       if (obj->has_dbf)
       {
              obj->has_dbf=0;
              gdbm_close(obj->dbf);
       }
       if (obj->prev_key)
       {
              free(obj->prev_key);
              obj->prev_key=0;
       }
}

Here is the caller graph for this function:

int gdbmobj_exists ( struct gdbmobj obj,
const char *  key,
size_t  keylen 
)

Definition at line 100 of file gdbmobj.c.

{
datum  dkey;

       if (!obj->has_dbf)   return (0);

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       if (gdbm_exists(obj->dbf, dkey))   return (1);
       return (0);
}
char* gdbmobj_fetch ( struct gdbmobj obj,
const char *  key,
size_t  keylen,
size_t *  datalen,
const char *  options 
)

Definition at line 115 of file gdbmobj.c.

{
char   *p;

       for (;;)
       {
              if ((p=gdbm_dofetch(obj, key, keylen, datalen)) != 0)
                     return (p);
              if (!options) break;
              if (*options == 'I')
              {
                     while (keylen && key[--keylen] != '.')
                            ;
                     if (!keylen)  break;
                     continue;
              }
              if (*options == 'D')
              {
              size_t i;

                     for (i=0; i<keylen; i++)
                            if (key[i] == '@') { ++i; break; }
                     if (i < keylen)
                     {
                            if ((p=gdbm_dofetch(obj, key, i, datalen)) != 0)
                                   return (p);
                            key += i;
                            keylen -= i;
                            continue;
                     }

                     for (i=0; i<keylen; i++)
                            if (key[i] == '.') { ++i; break; }
                     if (i < keylen)
                     {
                            key += i;
                            keylen -= i;
                            continue;
                     }
                     break;
              }
              break;
       }
       return (0);
}

Here is the call graph for this function:

void gdbmobj_init ( struct gdbmobj obj)

Definition at line 20 of file gdbmobj.c.

{
       obj->has_dbf=0;
       obj->prev_key=0;
       obj->prev_key_len=0;
}
int gdbmobj_open ( struct gdbmobj obj,
const char *  filename,
const char *  modestr 
)

Definition at line 41 of file gdbmobj.c.

{
int    mode=GDBM_READER;

       for ( ; *modestr; modestr++)
              switch (*modestr)    {
              case 'c':
              case 'C':
                     mode=GDBM_WRCREAT;
                     break;
              case 'w':
              case 'W':
                     mode=GDBM_WRITER;
                     break;
              case 'n':
              case 'N':
                     mode=GDBM_NEWDB;
                     break;
       }

       gdbmobj_close(obj);
       if ((obj->dbf=gdbm_open((char *)filename, 0, mode, 0664, 0)) != 0)
       {
              /* Where possible, set the close-on-exec bit */

#if    HAVE_GDBM_FDESC
#ifdef  FD_CLOEXEC

       int    fd=gdbm_fdesc(obj->dbf);

              if (fd >= 0)  fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif
#endif

              obj->has_dbf=1;
              return (0);
       }
       return (-1);
}

Here is the call graph for this function:

int gdbmobj_store ( struct gdbmobj obj,
const char *  key,
size_t  keylen,
const char *  data,
size_t  datalen,
const char *  mode 
)

Definition at line 81 of file gdbmobj.c.

{
datum dkey;
datum dval;

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       dval.dptr=(char *)data;
       dval.dsize=datalen;

       return (obj->has_dbf ? gdbm_store(obj->dbf, dkey, dval, (
                     *mode == 'i' || *mode == 'I' ?
                            GDBM_INSERT:GDBM_REPLACE)):-1);
}