Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | .\" Copyright (c) 1999 Tim Singletary .\" No copyright is claimed. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.8 2003/09/08 19:57:13 ru Exp $ .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. .Dd July 7, 1999 .Dt DBM 3 .Os .Sh NAME .Nm dbm_clearerr , .Nm dbm_close , .Nm dbm_delete , .Nm dbm_dirfno , .Nm dbm_error , .Nm dbm_fetch , .Nm dbm_firstkey , .Nm dbm_nextkey , .Nm dbm_open , .Nm dbm_store .Nd database access functions .Sh SYNOPSIS .In ndbm.h .Ft int .Fo dbm_clearerr .Fa "DBM *db" .Fc .Ft void .Fo dbm_close .Fa "DBM *db" .Fc .Ft int .Fo dbm_delete .Fa "DBM *db" .Fa "datum key" .Fc .Ft int .Fo dbm_dirfno .Fa "DBM *db" .Fc .Ft int .Fo dbm_error .Fa "DBM *db" .Fc .Ft datum .Fo dbm_fetch .Fa "DBM *db" .Fa "datum key" .Fc .Ft datum .Fo dbm_firstkey .Fa "DBM *db" .Fc .Ft datum .Fo dbm_nextkey .Fa "DBM *db" .Fc .Ft DBM * .Fo dbm_open .Fa "const char *file" .Fa "int open_flags" .Fa "mode_t file_mode" .Fc .Ft int .Fo dbm_store .Fa "DBM *db" .Fa "datum key" .Fa "datum content" .Fa "int store_mode" .Fc .Sh DESCRIPTION Database access functions. These functions are implemented using .Xr dbopen 3 with a .Xr hash 3 database. .Pp .Vt datum is declared in .In ndbm.h : .Bd -literal typedef struct { char *dptr; int dsize; } datum; .Ed .Pp The .Fn dbm_open file open_flags file_mode function opens or creates a database file. The .Fa file argument is the basename of the file containing the database; the actual database has a .Pa .db suffix. I.e., if .Fa file is .Qq Li /home/me/mystuff then the actual database is in the file .Pa /home/me/mystuff.db . The .Fa open_flags and .Fa file_mode arguments are passed to .Xr open 2 . .Pq Dv O_RDWR | O_CREAT is a typical value for .Fa open_flags ; .Li 0660 is a typical value for .Fa file_mode . .Dv O_WRONLY is treated as O_RDWR in .Fa open_flags . The pointer returned by .Fn dbm_open identifies the database and is the .Fa db argument to the other functions. The .Fn dbm_open function returns .Dv NULL and sets .Va errno if there were any errors. .Pp The .Fn dbm_close db function closes the database. The .Fn dbm_close function normally returns zero. .Pp The .Fn dbm_store db key content store_mode function inserts or replaces an entry in the database. The .Fa store_mode argument is either .Dv DBM_INSERT or .Dv DBM_REPLACE . If .Fa store_mode is .Dv DBM_INSERT and the database already contains an entry for .Fa key , that entry is not replaced. Otherwise the entry is replaced or inserted. The .Fn dbm_store function normally returns zero but returns 1 if the entry could not be inserted (because .Fa store_mode is .Dv DBM_INSERT , and an entry with .Fa key already exists) or returns -1 and sets .Va errno if there were any errors. .Pp The .Fn dbm_fetch db key function returns .Dv NULL or the .Fa content corresponding to .Fa key . .Pp The .Fn dbm_delete db key function deletes the entry for .Fa key . The .Fn dbm_delete function normally returns zero but returns 1 if there was no entry with .Fa key in the database or returns -1 and sets .Va errno if there were any errors. .Pp The .Fn dbm_firstkey db function returns the first key in the database. The .Fn dbm_nextkey db function returns subsequent keys. The .Fn db_firstkey function must be called before .Fn dbm_nextkey . The order in which keys are returned is unspecified and may appear random. The .Fn dbm_nextkey function returns .Dv NULL after all keys have been returned. .Pp The .Fn dbm_error db function returns the .Va errno value of the most recent error. The .Fn dbm_clearerr db function resets this value to 0 and returns 0. .Pp The .Fn dbm_dirfno db function returns the file descriptor to the database. .Sh LEGACY SYNOPSIS .Fd #include <fcntl.h> .Fd #include <ndbm.h> .Pp The include file .In ndbm.h is necessary for all functions. .Pp .Ft DBM * .br .Fo dbm_open .Fa "const char *file" .Fa "int open_flags" .Fa "int file_mode" .Fc ; .Pp .Fa file_mode has type .Vt int . .Sh SEE ALSO .Xr open 2 , .Xr dbopen 3 , .Xr hash 3 , .Xr compat 5 .Sh STANDARDS These functions (except .Fn dbm_dirfno ) are included in the .St -susv2 . |