Imported Upstream version 1.10
[platform/upstream/gdbm.git] / src / gdbm.h
1 /* gdbm.h  -  The include file for dbm users.  -*- c -*- */
2
3 /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
4     Copyright (C) 1990, 1991, 1993, 2011 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. If not, see <http://www.gnu.org/licenses/>.  
18
19     You may contact the author by:
20        e-mail:  phil@cs.wwu.edu
21       us-mail:  Philip A. Nelson
22                 Computer Science Department
23                 Western Washington University
24                 Bellingham, WA 98226
25        
26 *************************************************************************/
27
28 /* Protection for multiple includes. */
29 #ifndef _GDBM_H_
30 # define _GDBM_H_
31
32 /* GDBM C++ support */
33 # if defined(__cplusplus) || defined(c_plusplus)
34 extern "C" {
35 # endif
36
37 /* Parameters to gdbm_open for READERS, WRITERS, and WRITERS who
38    can create the database. */
39 # define GDBM_READER    0       /* A reader. */
40 # define GDBM_WRITER    1       /* A writer. */
41 # define GDBM_WRCREAT   2       /* A writer.  Create the db if needed. */
42 # define GDBM_NEWDB     3       /* A writer.  Always create a new db. */
43 # define GDBM_OPENMASK  7       /* Mask for the above. */
44
45 # define GDBM_FAST      0x010   /* Write fast! => No fsyncs.  OBSOLETE. */
46 # define GDBM_SYNC      0x020   /* Sync operations to the disk. */
47 # define GDBM_NOLOCK    0x040   /* Don't do file locking operations. */
48 # define GDBM_NOMMAP    0x080   /* Don't use mmap(). */
49 # define GDBM_CLOEXEC   0x100   /* Close the underlying fd on exec(3) */
50   
51 /* Parameters to gdbm_store for simple insertion or replacement in the
52    case that the key is already in the database. */
53 # define GDBM_INSERT    0       /* Never replace old data with new. */
54 # define GDBM_REPLACE   1       /* Always replace old data with new. */
55
56 /* Parameters to gdbm_setopt, specifing the type of operation to perform. */
57 # define GDBM_SETCACHESIZE    1  /* Set the cache size. */
58 # define GDBM_FASTMODE        2 /* Toggle fast mode.  OBSOLETE. */
59 # define GDBM_SETSYNCMODE     3  /* Turn on or off sync operations. */
60 # define GDBM_SETCENTFREE     4  /* Keep all free blocks in the header. */
61 # define GDBM_SETCOALESCEBLKS 5  /* Attempt to coalesce free blocks. */
62 # define GDBM_SETMAXMAPSIZE   6  /* Set maximum mapped memory size */
63 # define GDBM_SETMMAP         7  /* Toggle mmap mode */
64
65 /* Compatibility defines: */
66 # define GDBM_CACHESIZE      GDBM_SETCACHESIZE
67 # define GDBM_SYNCMODE       GDBM_SETSYNCMODE
68 # define GDBM_CENTFREE       GDBM_SETCENTFREE
69 # define GDBM_COALESCEBLKS   GDBM_SETCOALESCEBLKS
70
71 # define GDBM_GETFLAGS        8  /* Get gdbm_open flags */
72 # define GDBM_GETMMAP         9  /* Get mmap status */
73 # define GDBM_GETCACHESIZE    10 /* Get current cache side */
74 # define GDBM_GETSYNCMODE     11 /* Get synch mode */
75 # define GDBM_GETCENTFREE     12 /* Get "centfree" status */
76 # define GDBM_GETCOALESCEBLKS 13 /* Get free block coalesce status */
77 # define GDBM_GETMAXMAPSIZE   14 /* Get maximum mapped memory size */
78 # define GDBM_GETDBNAME       15 /* Return database file name */
79
80 /* The data and key structure. */
81 typedef struct {
82         char *dptr;
83         int   dsize;
84       } datum;
85
86
87 /* The file information header. This is good enough for most applications. */
88 typedef struct gdbm_file_info *GDBM_FILE;
89
90 /* External variable, the gdbm build release string. */
91 extern const char *gdbm_version;        
92
93 # define GDBM_VERSION_MAJOR 1
94 # define GDBM_VERSION_MINOR 10
95 # define GDBM_VERSION_PATCH 0
96
97 extern int const gdbm_version_number[3];
98
99 /* GDBM external functions. */
100
101 extern GDBM_FILE gdbm_open (const char *, int, int, int,
102                             void (*)(const char *));
103 extern void gdbm_close (GDBM_FILE);
104 extern int gdbm_store (GDBM_FILE, datum, datum, int);
105 extern datum gdbm_fetch (GDBM_FILE, datum);
106 extern int gdbm_delete (GDBM_FILE, datum);
107 extern datum gdbm_firstkey (GDBM_FILE);
108 extern datum gdbm_nextkey (GDBM_FILE, datum);
109 extern int gdbm_reorganize (GDBM_FILE);
110 extern void gdbm_sync (GDBM_FILE);
111 extern int gdbm_exists (GDBM_FILE, datum);
112 extern int gdbm_setopt (GDBM_FILE, int, void *, int);
113 extern int gdbm_fdesc (GDBM_FILE);
114 extern int gdbm_export (GDBM_FILE, const char *, int, int);
115 extern int gdbm_import (GDBM_FILE, const char *, int);
116
117 # define GDBM_NO_ERROR          0
118 # define GDBM_MALLOC_ERROR      1
119 # define GDBM_BLOCK_SIZE_ERROR  2
120 # define GDBM_FILE_OPEN_ERROR   3
121 # define GDBM_FILE_WRITE_ERROR  4
122 # define GDBM_FILE_SEEK_ERROR   5
123 # define GDBM_FILE_READ_ERROR   6
124 # define GDBM_BAD_MAGIC_NUMBER  7
125 # define GDBM_EMPTY_DATABASE    8
126 # define GDBM_CANT_BE_READER    9
127 # define GDBM_CANT_BE_WRITER    10
128 # define GDBM_READER_CANT_DELETE        11
129 # define GDBM_READER_CANT_STORE 12
130 # define GDBM_READER_CANT_REORGANIZE    13
131 # define GDBM_UNKNOWN_UPDATE    14
132 # define GDBM_ITEM_NOT_FOUND    15
133 # define GDBM_REORGANIZE_FAILED 16
134 # define GDBM_CANNOT_REPLACE    17
135 # define GDBM_ILLEGAL_DATA      18
136 # define GDBM_OPT_ALREADY_SET   19
137 # define GDBM_OPT_ILLEGAL       20
138 # define GDBM_BYTE_SWAPPED      21
139 # define GDBM_BAD_FILE_OFFSET   22
140 # define GDBM_BAD_OPEN_FLAGS    23
141 # define GDBM_FILE_STAT_ERROR   24
142 # define GDBM_FILE_EOF          25
143
144 # define _GDBM_MIN_ERRNO                0
145 # define _GDBM_MAX_ERRNO                GDBM_FILE_EOF
146 typedef int gdbm_error;         /* For compatibilities sake. */
147 extern gdbm_error gdbm_errno;
148 extern const char * const gdbm_errlist[];
149
150 /* extra prototypes */
151
152 extern const char *gdbm_strerror (gdbm_error);
153 extern int gdbm_version_cmp (int const a[], int const b[]);
154
155 # if defined(__cplusplus) || defined(c_plusplus)
156 }
157 # endif
158
159 #endif