📄 dbm.c
字号:
#ifndef lintstatic char *sccsid = "@(#)dbm.c 4.1 ULTRIX 7/2/90";#endif lint/* * Copyright (c) 1989 by * Digital Equipment Corporation, Maynard, MA * All rights reserved. * * This software is furnished under a license and may be used and * copied only in accordance with the terms of such license and * with the inclusion of the above copyright notice. This * software or any other copies thereof may not be provided or * otherwise made available to any other person. No title to and * ownership of the software is hereby transferred. * * This software is derived from software received from the * University of California, Berkeley, and from Bell * Laboratories. Use, duplication, or disclosure is subject to * restrictions under license agreements with University of * California and with AT&T. * * The information in this software is subject to change without * notice and should not be construed as a commitment by Digital * Equipment Corporation. * * Digital assumes no responsibility for the use or reliability * of its software on equipment which is not supplied by Digital. *//* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * * "dbm.c 5.3 (Berkeley) 85/08/15"; *//* * Modification History * * 11/13/89 J.Friedman * Replaced dbm.[ch] with new 4.3 dbm.[ch] based on ndbm calls * Note only use include/dbm.h source now, not libdbm/dbm.h * * 11/16/89 J.Friedman * Added dbmclose() for backward compatibility, even though undoumented */#include <dbm.h>#define NODB ((DBM *)0)static DBM *cur_db = NODB;static char no_db[] = "dbm: no open database\n";dbminit(file) char *file;{ if (cur_db != NODB) dbm_close(cur_db); cur_db = dbm_open(file, 2, 0); if (cur_db == NODB) { cur_db = dbm_open(file, 0, 0); if (cur_db == NODB) return (-1); } return (0);}intdbmclose(){ dbm_close(cur_db); return(0);}longforder(key)datum key;{ if (cur_db == NODB) { printf(no_db); return (0L); } return (dbm_forder(cur_db, key));}datumfetch(key)datum key;{ datum item; if (cur_db == NODB) { printf(no_db); item.dptr = 0; return (item); } return (dbm_fetch(cur_db, key));}delete(key)datum key;{ if (cur_db == NODB) { printf(no_db); return (-1); } if (dbm_rdonly(cur_db)) return (-1); return (dbm_delete(cur_db, key));}store(key, dat)datum key, dat;{ if (cur_db == NODB) { printf(no_db); return (-1); } if (dbm_rdonly(cur_db)) return (-1); return (dbm_store(cur_db, key, dat, DBM_REPLACE));}datumfirstkey(){ datum item; if (cur_db == NODB) { printf(no_db); item.dptr = 0; return (item); } return (dbm_firstkey(cur_db));}datumnextkey(key)datum key;{ datum item; if (cur_db == NODB) { printf(no_db); item.dptr = 0; return (item); } return (dbm_nextkey(cur_db, key));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -