diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-07-08 11:28:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-07-08 14:12:34 +0300 |
commit | 4aef6b36f862e46723403bc6422ac47058a5ef19 (patch) | |
tree | fa7afe6ed8f1abf080fa764bda1bbc81e07f407b /doc | |
parent | 260102cf7f75db3c87d04a06eb8054853cacce97 (diff) | |
download | gdbm-4aef6b36f862e46723403bc6422ac47058a5ef19.tar.gz gdbm-4aef6b36f862e46723403bc6422ac47058a5ef19.tar.bz2 |
Fix error handling in gdbm_fetch, gdbm_firstkey, and gdbm_nextkey.
* src/gdbmfetch.c: Hanlde out of memory error.
* src/findkey.c: Set gdbm_errno to GDBM_ITEM_NOT_FOUND
if nothing was found.
* src/gdbmdelete.c: Don't set gdbm_errno after
_gdbm_findkey returns -1. It's been done already.
* src/gdbmexp.c (gdbm_export_to_file): Return -1 if
gdbm_fetch fails.
* src/gdbmseq.c (get_next_key): Set gdbm_errno to
GDBM_ITEM_NOT_FOUND if there's no next key.
Don't call _gdbm_fatal on out of memory condition.
(gdbm_nextkey): Set gdbm_errno to
GDBM_ITEM_NOT_FOUND if there's no next key.
* src/gdbmtool.c (fetch_handler)
(firstkey_handler,nextkey_handler): Check gdbm_errno.
* src/gdbmstore.c: Handle error return from _gdbm_findkey.
* tests/gtdump.c: Likewise.
* tests/gtfetch.c: Likewise.
* doc/gdbm.texi: Document changes.
* doc/gdbm.3: Likewise.
* configure.ac: Version 1.12.90
* NEWS: Update.
* .gitignore: Update.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/gdbm.3 | 23 | ||||
-rw-r--r-- | doc/gdbm.texi | 20 |
2 files changed, 29 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | .\" This file is part of GDBM. | 1 | .\" This file is part of GDBM. |
2 | .\" Copyright (C) 2011, 2013 Free Software Foundation, Inc. | 2 | .\" Copyright (C) 2011, 2013, 2016 Free Software Foundation, Inc. |
3 | .\" | 3 | .\" |
4 | .\" GDBM is free software; you can redistribute it and/or modify | 4 | .\" GDBM is free software; you can redistribute it and/or modify |
5 | .\" it under the terms of the GNU General Public License as published by | 5 | .\" it under the terms of the GNU General Public License as published by |
@@ -13,7 +13,7 @@ | |||
13 | .\" | 13 | .\" |
14 | .\" You should have received a copy of the GNU General Public License | 14 | .\" You should have received a copy of the GNU General Public License |
15 | .\" along with GDBM. If not, see <http://www.gnu.org/licenses/>. */ | 15 | .\" along with GDBM. If not, see <http://www.gnu.org/licenses/>. */ |
16 | .TH GDBM 3 "July 6, 2016" "GDBM" "GDBM User Reference" | 16 | .TH GDBM 3 "July 8, 2016" "GDBM" "GDBM User Reference" |
17 | .SH NAME | 17 | .SH NAME |
18 | GDBM \- The GNU database manager. Includes \fBdbm\fR and \fBndbm\fR | 18 | GDBM \- The GNU database manager. Includes \fBdbm\fR and \fBndbm\fR |
19 | compatibility. | 19 | compatibility. |
@@ -171,7 +171,7 @@ if it detects a fatal error. The only parameter of this function is a string. | |||
171 | If the value of 0 is provided, \fBgdbm\fR will use a default function. | 171 | If the value of 0 is provided, \fBgdbm\fR will use a default function. |
172 | 172 | ||
173 | The return value is the pointer needed by all other routines to | 173 | The return value is the pointer needed by all other routines to |
174 | access that gdbm file. If the return is the NULL pointer, \fBgdbm_open\fR | 174 | access that gdbm file. If the return is the \fBNULL\fR pointer, \fBgdbm_open\fR |
175 | was not successful. The errors can be found in \fIgdbm_errno\fR for gdbm | 175 | was not successful. The errors can be found in \fIgdbm_errno\fR for gdbm |
176 | errors and in \fIerrno\fR for system errors. (For error codes, see | 176 | errors and in \fIerrno\fR for system errors. (For error codes, see |
177 | gdbmerrno.h.) | 177 | gdbmerrno.h.) |
@@ -218,8 +218,12 @@ To search for some data, use: | |||
218 | \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is | 218 | \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is |
219 | the key data. | 219 | the key data. |
220 | 220 | ||
221 | If the \fIdptr\fR element of the return value is NULL, no data was | 221 | If the \fIdptr\fR element of the return value is \fBNULL\fR, the |
222 | found. Otherwise the return value is a pointer to the found data. | 222 | \fBgdbm_errno\fR variable should be examined. The value of |
223 | \fBGDBM_ITEM_NOT_FOUND\fR means no data was found for that \fIkey\fR. | ||
224 | Other value means an error occurred. | ||
225 | |||
226 | Otherwise the return value is a pointer to the found data. | ||
223 | The storage space for the \fIdptr\fR element is allocated using | 227 | The storage space for the \fIdptr\fR element is allocated using |
224 | \fBmalloc(3)\fR. \fBGdbm\fI does not automatically free this data. | 228 | \fBmalloc(3)\fR. \fBGdbm\fI does not automatically free this data. |
225 | It is the programmer's responsibility to free this storage when it is | 229 | It is the programmer's responsibility to free this storage when it is |
@@ -259,8 +263,11 @@ the database once. (The order has to do with the hash values.) | |||
259 | key data. | 263 | key data. |
260 | 264 | ||
261 | The return values are both of type \fBdatum\fR. If the \fIdptr\fR | 265 | The return values are both of type \fBdatum\fR. If the \fIdptr\fR |
262 | element of the return value is NULL, there is no first key or next key. | 266 | element of the return value is \fBNULL\fR, inspect the |
263 | Again notice that \fIdptr\fR points to data allocated by \fBmalloc(3)\fR | 267 | \fBgdbm_errno\fR. If it is \fBGDBM_ITEM_NOT_FOUND\fR, there is no |
268 | first key or next key. Otherwise, an error occurred. | ||
269 | |||
270 | Again, notice that \fIdptr\fR points to data allocated by \fBmalloc(3)\fR | ||
264 | and \fBgdbm\fR will not free it for you. | 271 | and \fBgdbm\fR will not free it for you. |
265 | 272 | ||
266 | These functions were intended to visit the database in read-only algorithms, | 273 | These functions were intended to visit the database in read-only algorithms, |
@@ -426,7 +433,7 @@ Send bug reports to <bug\-gdbm@gnu.org>. | |||
426 | .SH AUTHORS | 433 | .SH AUTHORS |
427 | by Philip A. Nelson, Jason Downs and Sergey Poznyakoff. | 434 | by Philip A. Nelson, Jason Downs and Sergey Poznyakoff. |
428 | .SH COPYRIGHT | 435 | .SH COPYRIGHT |
429 | Copyright \(co 1990 - 2011 Free Software Foundation, Inc. | 436 | Copyright \(co 1990 - 2016 Free Software Foundation, Inc. |
430 | 437 | ||
431 | GDBM is free software; you can redistribute it and/or modify | 438 | GDBM is free software; you can redistribute it and/or modify |
432 | it under the terms of the GNU General Public License as published by | 439 | it under the terms of the GNU General Public License as published by |
diff --git a/doc/gdbm.texi b/doc/gdbm.texi index 6322a9b..6fad9d9 100644 --- a/doc/gdbm.texi +++ b/doc/gdbm.texi | |||
@@ -43,7 +43,7 @@ Published by the Free Software Foundation, | |||
43 | 51 Franklin Street, Fifth Floor | 43 | 51 Franklin Street, Fifth Floor |
44 | Boston, MA 02110-1301, USA | 44 | Boston, MA 02110-1301, USA |
45 | 45 | ||
46 | Copyright @copyright{} 1989-1999, 2007-2011 Free Software Foundation, Inc. | 46 | Copyright @copyright{} 1989-1999, 2007-2016 Free Software Foundation, Inc. |
47 | 47 | ||
48 | Permission is granted to copy, distribute and/or modify this document | 48 | Permission is granted to copy, distribute and/or modify this document |
49 | under the terms of the GNU Free Documentation License, Version 1.3 or | 49 | under the terms of the GNU Free Documentation License, Version 1.3 or |
@@ -430,7 +430,11 @@ The @samp{dptr} field in the structure that is returned points to a | |||
430 | memory block allocated by @code{malloc}. It is the caller's | 430 | memory block allocated by @code{malloc}. It is the caller's |
431 | responsibility to free it when no longer needed. | 431 | responsibility to free it when no longer needed. |
432 | 432 | ||
433 | If the @samp{dptr} is @samp{NULL}, no data was found. | 433 | If the @samp{dptr} is @samp{NULL}, inspect the value of the |
434 | @code{gdbm_errno} variable (@pxref{Variables,gdbm_errno}). If it is | ||
435 | @samp{GDBM_ITEM_NOT_FOUND}, no data was found. Any other value means an | ||
436 | error occurred. Use @code{gdbm_strerror} function to convert | ||
437 | @code{gdbm_errno} to a human-readable string. | ||
434 | 438 | ||
435 | The parameters are: | 439 | The parameters are: |
436 | 440 | ||
@@ -515,8 +519,10 @@ access is not @code{key} sequential, but it is guaranteed to visit every | |||
515 | @deftypefn {gdbm interface} datum gdbm_firstkey (GDBM_FILE @var{dbf}) | 519 | @deftypefn {gdbm interface} datum gdbm_firstkey (GDBM_FILE @var{dbf}) |
516 | Initiate sequential access to the database @var{dbf}. The returned | 520 | Initiate sequential access to the database @var{dbf}. The returned |
517 | value is the first key accessed in the database. If the @samp{dptr} | 521 | value is the first key accessed in the database. If the @samp{dptr} |
518 | field in the returned datum is @samp{NULL}, the database contains no | 522 | field in the returned datum is @samp{NULL}, inspect the |
519 | data. | 523 | @code{gdbm_errno} variable (@pxref{Variables, gdbm_errno}). The value |
524 | of @code{GDBM_ITEM_NOT_FOUND} means that the database contains no | ||
525 | data. Other value means an error occurred. | ||
520 | 526 | ||
521 | Otherwise, @samp{dptr} points to a memory block obtained from | 527 | Otherwise, @samp{dptr} points to a memory block obtained from |
522 | @code{malloc}, which holds the key value. The caller is responsible | 528 | @code{malloc}, which holds the key value. The caller is responsible |
@@ -530,8 +536,10 @@ value returned from a previous call to @code{gdbm_nextkey} or | |||
530 | @code{gdbm_firstkey}. | 536 | @code{gdbm_firstkey}. |
531 | 537 | ||
532 | The function returns next key from the database. If the @samp{dptr} | 538 | The function returns next key from the database. If the @samp{dptr} |
533 | field in the returned datum is @samp{NULL}, all keys in the database | 539 | field in the returned datum is @samp{NULL} inspect the |
534 | has been visited. | 540 | @code{gdbm_errno} variable (@pxref{Variables, gdbm_errno}). The value |
541 | of @code{GDBM_ITEM_NOT_FOUND} means that all keys in the database | ||
542 | has been visited. Any other value means an error occurred. | ||
535 | 543 | ||
536 | Otherwise, @samp{dptr} points to a memory block obtained from | 544 | Otherwise, @samp{dptr} points to a memory block obtained from |
537 | @code{malloc}, which holds the key value. The caller is responsible | 545 | @code{malloc}, which holds the key value. The caller is responsible |