Annotation of 43BSDReno/lib/libdbm/dbm.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1985 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)dbm.c      5.5 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include       "dbm.h"
                     25: 
                     26: #define        NODB    ((DBM *)0)
                     27: 
                     28: static DBM *cur_db = NODB;
                     29: 
                     30: static char no_db[] = "dbm: no open database\n";
                     31: 
                     32: dbminit(file)
                     33:        char *file;
                     34: {
                     35:        if (cur_db != NODB)
                     36:                dbm_close(cur_db);
                     37: 
                     38:        cur_db = dbm_open(file, 2, 0);
                     39:        if (cur_db == NODB) {
                     40:                cur_db = dbm_open(file, 0, 0);
                     41:                if (cur_db == NODB)
                     42:                        return (-1);
                     43:        }
                     44:        return (0);
                     45: }
                     46: 
                     47: long
                     48: forder(key)
                     49: datum key;
                     50: {
                     51:        if (cur_db == NODB) {
                     52:                printf(no_db);
                     53:                return (0L);
                     54:        }
                     55:        return (dbm_forder(cur_db, key));
                     56: }
                     57: 
                     58: datum
                     59: fetch(key)
                     60: datum key;
                     61: {
                     62:        datum item;
                     63: 
                     64:        if (cur_db == NODB) {
                     65:                printf(no_db);
                     66:                item.dptr = 0;
                     67:                return (item);
                     68:        }
                     69:        return (dbm_fetch(cur_db, key));
                     70: }
                     71: 
                     72: delete(key)
                     73: datum key;
                     74: {
                     75:        if (cur_db == NODB) {
                     76:                printf(no_db);
                     77:                return (-1);
                     78:        }
                     79:        if (dbm_rdonly(cur_db))
                     80:                return (-1);
                     81:        return (dbm_delete(cur_db, key));
                     82: }
                     83: 
                     84: store(key, dat)
                     85: datum key, dat;
                     86: {
                     87:        if (cur_db == NODB) {
                     88:                printf(no_db);
                     89:                return (-1);
                     90:        }
                     91:        if (dbm_rdonly(cur_db))
                     92:                return (-1);
                     93: 
                     94:        return (dbm_store(cur_db, key, dat, DBM_REPLACE));
                     95: }
                     96: 
                     97: datum
                     98: firstkey()
                     99: {
                    100:        datum item;
                    101: 
                    102:        if (cur_db == NODB) {
                    103:                printf(no_db);
                    104:                item.dptr = 0;
                    105:                return (item);
                    106:        }
                    107:        return (dbm_firstkey(cur_db));
                    108: }
                    109: 
                    110: datum
                    111: nextkey(key)
                    112: datum key;
                    113: {
                    114:        datum item;
                    115: 
                    116:        if (cur_db == NODB) {
                    117:                printf(no_db);
                    118:                item.dptr = 0;
                    119:                return (item);
                    120:        }
                    121:        return (dbm_nextkey(cur_db, key));
                    122: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.