1 /* gdbm.h - The include file for dbm users. */ 2 3 /* This file is part of GDBM, the GNU data base manager, by Philip A. Nelson. 4 Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc. 5 6 GDBM is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GDBM is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GDBM; see the file COPYING. If not, write to 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 20 You may contact the author by: 21 e-mail: phil@cs.wwu.edu 22 us-mail: Philip A. Nelson 23 Computer Science Department 24 Western Washington University 25 Bellingham, WA 98226 26 27 *************************************************************************/ 28 29 /* Protection for multiple includes. */ 30 #ifndef _GDBM_H_ 31 #define _GDBM_H_ 32 33 /* Parameters to gdbm_open for READERS, WRITERS, and WRITERS who 34 can create the database. */ 35 #define GDBM_READER 0 /* A reader. */ 36 #define GDBM_WRITER 1 /* A writer. */ 37 #define GDBM_WRCREAT 2 /* A writer. Create the db if needed. */ 38 #define GDBM_NEWDB 3 /* A writer. Always create a new db. */ 39 #define GDBM_FAST 16 /* Write fast! => No fsyncs. */ 40 41 /* Parameters to gdbm_store for simple insertion or replacement in the 42 case that the key is already in the database. */ 43 #define GDBM_INSERT 0 /* Never replace old data with new. */ 44 #define GDBM_REPLACE 1 /* Always replace old data with new. */ 45 46 /* Parameters to gdbm_setopt, specifing the type of operation to perform. */ 47 #define GDBM_CACHESIZE 1 /* Set the cache size. */ 48 #define GDBM_FASTMODE 2 /* Toggle fast mode. */ 49 50 /* The data and key structure. This structure is defined for compatibility. */ 51 typedef struct { 52 char *dptr; 53 int dsize; 54 } datum; 55 56 57 /* The file information header. This is good enough for most applications. */ 58 typedef struct {int dummy[10];} *GDBM_FILE; 59 60 /* Determine if the C(++) compiler requires complete function prototype */ 61 #if __STDC__ || defined(__cplusplus) || defined(c_plusplus) 62 #define GDBM_Proto(x) x 63 #else 64 #define GDBM_Proto(x) () 65 #endif /* NeedFunctionPrototypes */ 66 67 /* External variable, the gdbm build release string. */ 68 extern char *gdbm_version; 69 70 71 /* GDBM C++ support */ 72 #if defined(__cplusplus) || defined(c_plusplus) 73 extern "C" { 74 #endif 75 76 /* These are the routines! */ 77 78 extern GDBM_FILE gdbm_open GDBM_Proto(( 79 char *file, 80 int block_size, 81 int flags, 82 int mode, 83 void (*fatal_func)() 84 )); 85 86 extern void gdbm_close GDBM_Proto(( 87 GDBM_FILE dbf 88 )); 89 90 extern int gdbm_store GDBM_Proto(( 91 GDBM_FILE dbf, 92 datum key, 93 datum content, 94 int flags 95 )); 96 97 extern datum gdbm_fetch GDBM_Proto(( 98 GDBM_FILE dbf, 99 datum key 100 )); 101 102 extern int gdbm_delete GDBM_Proto(( 103 GDBM_FILE dbf, 104 datum key 105 )); 106 107 extern datum gdbm_firstkey GDBM_Proto(( 108 GDBM_FILE dbf 109 )); 110 111 extern datum gdbm_nextkey GDBM_Proto(( 112 GDBM_FILE dbf, 113 datum key 114 )); 115 116 extern int gdbm_reorganize GDBM_Proto(( 117 GDBM_FILE dbf 118 )); 119 120 extern void gdbm_sync GDBM_Proto(( 121 GDBM_FILE dbf 122 )); 123 124 extern int gdbm_exists GDBM_Proto(( 125 GDBM_FILE dbf, 126 datum key 127 )); 128 129 extern int gdbm_setopt GDBM_Proto(( 130 GDBM_FILE dbf, 131 int optflag, 132 int *optval, 133 int optlen 134 )); 135 136 #if defined(__cplusplus) || defined(c_plusplus) 137 } 138 #endif 139 140 /* gdbm sends back the following error codes in the variable gdbm_errno. */ 141 typedef enum { GDBM_NO_ERROR, 142 GDBM_MALLOC_ERROR, 143 GDBM_BLOCK_SIZE_ERROR, 144 GDBM_FILE_OPEN_ERROR, 145 GDBM_FILE_WRITE_ERROR, 146 GDBM_FILE_SEEK_ERROR, 147 GDBM_FILE_READ_ERROR, 148 GDBM_BAD_MAGIC_NUMBER, 149 GDBM_EMPTY_DATABASE, 150 GDBM_CANT_BE_READER, 151 GDBM_CANT_BE_WRITER, 152 GDBM_READER_CANT_DELETE, 153 GDBM_READER_CANT_STORE, 154 GDBM_READER_CANT_REORGANIZE, 155 GDBM_UNKNOWN_UPDATE, 156 GDBM_ITEM_NOT_FOUND, 157 GDBM_REORGANIZE_FAILED, 158 GDBM_CANNOT_REPLACE, 159 GDBM_ILLEGAL_DATA, 160 GDBM_OPT_ALREADY_SET, 161 GDBM_OPT_ILLEGAL} 162 gdbm_error; 163 extern gdbm_error gdbm_errno; 164 165 /* extra prototypes */ 166 167 /* GDBM C++ support */ 168 #if defined(__cplusplus) || defined(c_plusplus) 169 extern "C" { 170 #endif 171 172 extern const char *gdbm_strerror GDBM_Proto(( 173 gdbm_error error 174 )); 175 176 #if defined(__cplusplus) || defined(c_plusplus) 177 } 178 #endif 179 180 #endif 181