summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/hcreate.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdlib/hcreate.3')
-rw-r--r--lib/libc/stdlib/hcreate.393
1 files changed, 81 insertions, 12 deletions
diff --git a/lib/libc/stdlib/hcreate.3 b/lib/libc/stdlib/hcreate.3
index 2466c9f..2161f92 100644
--- a/lib/libc/stdlib/hcreate.3
+++ b/lib/libc/stdlib/hcreate.3
@@ -28,11 +28,16 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 6, 2008
+.Dd July 21, 2014
.Dt HCREATE 3
.Os
.Sh NAME
-.Nm hcreate , hdestroy , hsearch
+.Nm hcreate ,
+.Nm hcreate_r ,
+.Nm hdestroy ,
+.Nm hdestroy_r ,
+.Nm hsearch ,
+.Nm hsearch_r
.Nd manage hash search table
.Sh LIBRARY
.Lb libc
@@ -40,16 +45,25 @@
.In search.h
.Ft int
.Fn hcreate "size_t nel"
+.Ft int
+.Fn hcreate_r "size_t nel" "struct hsearch_data *table"
+.Ft void
+.Fn hdestroy "void"
.Ft void
-.Fn hdestroy void
+.Fn hdestroy_r "struct hsearch_data *table"
.Ft ENTRY *
.Fn hsearch "ENTRY item" "ACTION action"
+.Ft int
+.Fn hsearch_r "ENTRY item" "ACTION action" "ENTRY ** itemp" "struct hsearch_data *table"
.Sh DESCRIPTION
The
.Fn hcreate ,
+.Fn hcreate_r ,
.Fn hdestroy ,
+.Fn hdestroy_r
+.Fn hsearch ,
and
-.Fn hsearch
+.Fn hsearch_r
functions manage hash search tables.
.Pp
The
@@ -90,7 +104,7 @@ argument is a structure of type
.Vt ENTRY
(defined in the
.In search.h
-header) containing two pointers:
+header) that contains two pointers:
.Fa item.key
points to the comparison key (a
.Vt "char *" ) ,
@@ -136,21 +150,50 @@ is
and
.Fn hdestroy
is called.
+.Pp
+The
+.Fn hcreate_r ,
+.Fn hdestroy_r ,
+and
+.Fn hsearch_r
+functions are re-entrant versions of the above functions that can
+operate on a table supplied by the user.
+The
+.Fn hsearch_r
+function returns
+.Dv 0
+if the action is
+.Dv ENTER
+and the element cannot be created,
+.Dv 1
+otherwise.
+If the element exists or can be created, it will be placed in
+.Fa itemp ,
+otherwise
+.Fa itemp
+will be set to
+.Dv NULL .
.Sh RETURN VALUES
The
.Fn hcreate
-function returns 0 if the table creation failed and the global variable
+and
+.Fn hcreate_r
+functions return 0 if the table creation failed and the global variable
.Va errno
is set to indicate the error;
otherwise, a non-zero value is returned.
.Pp
The
.Fn hdestroy
-function does not return a value.
+and
+.Fn hdestroy_r
+functions return no value.
.Pp
The
.Fn hsearch
-function returns a
+and
+.Fn hsearch_r
+functions return a
.Dv NULL
pointer if either the
.Fa action
@@ -223,15 +266,31 @@ main(void)
.Sh ERRORS
The
.Fn hcreate
-and
+.Fn hcreate_r ,
.Fn hsearch
-functions may fail if:
+and
+.Fn hsearch_r
+functions will fail if:
.Bl -tag -width Er
.It Bq Er ENOMEM
-Insufficient storage space is available.
+Insufficient memory is available.
.It Bq Er EINVAL
A table already exists.
.El
+.Pp
+The
+.Fn hsearch
+and
+.Fn hsearch_r
+functions will also fail if the action is
+.Dv SEARCH
+and the element is not found:
+.Bl -tag -width Er
+.It Bq Er ESRCH
+The
+.Fa item
+given is not found.
+.El
.Sh SEE ALSO
.Xr bsearch 3 ,
.Xr lsearch 3 ,
@@ -254,5 +313,15 @@ and
.Fn hsearch
functions first appeared in
.At V .
+The
+.Fn hcreate_r ,
+.Fn hdestroy_r
+and
+.Fn hsearch_r
+functions are
+.Tn GNU
+extensions.
.Sh BUGS
-The interface permits the use of only one hash table at a time.
+The original,
+.Pf non- Tn GNU
+interface permits the use of only one hash table at a time.
OpenPOWER on IntegriCloud