.sp
.BI "int hcreate_r(size_t " nel ", struct hsearch_data *" tab );
.sp
-.BI "int hsearch_r(ENTRY " item ", ACTION " action ", ENTRY **" ret ,
+.BI "int hsearch_r(ENTRY " item ", ACTION " action ", ENTRY **" ret ,
.BI " struct hsearch_data *" tab );
.sp
.BI "void hdestroy_r(struct hsearch_data *" tab );
.RS
.sp
.nf
-typedef struct entry {
+typedef struct entry {
char *\fIkey\fP;
- void *\fIdata\fP;
+ void *\fIdata\fP;
} ENTRY;
.RE
.fi
.BR strcmp (3)),
and if successful returns a pointer to it.
The argument \fIaction\fP determines what \fBhsearch\fP() does
-after an unsuccessful search. A value of \fBENTER\fP instructs it to
+after an unsuccessful search.
+A value of \fBENTER\fP instructs it to
insert a copy of \fIitem\fP, while a value of \fBFIND\fP means to return
NULL.
.PP
.BR hsearch_r (),
.BR hdestroy_r ()
are reentrant versions that allow the use of more than one table.
-The last argument used identifies the table. The struct it points to
+The last argument used identifies the table.
+The struct it points to
must be zeroed before the first call to
.BR hcreate_r ().
.SH "RETURN VALUE"
.SH BUGS
SVr4 and POSIX.1-2001 specify that \fIaction\fP
is significant only for unsuccessful searches, so that an ENTER
-should not do anything for a successful search. The libc and glibc
+should not do anything for a successful search.
+The libc and glibc
implementations update the \fIdata\fP for the given \fIkey\fP
in this case.
.\" Tue Jan 29 09:27:40 2002: fixed in latest glibc snapshot
#include <stdio.h>
#include <stdlib.h>
#include <search.h>
-
+
char *data[] = { "alpha", "bravo", "charlie", "delta",
"echo", "foxtrot", "golf", "hotel", "india", "juliet",
"kilo", "lima", "mike", "november", "oscar", "papa",
"quebec", "romeo", "sierra", "tango", "uniform",
- "victor", "whisky", "x-ray", "yankee", "zulu"
+ "victor", "whisky", "x-ray", "yankee", "zulu"
};
-int
-main(void)
+int
+main(void)
{
ENTRY e, *ep;
int i;
-
+
/* starting with small table, and letting it grow does not work */
hcreate(30);
for (i = 0; i < 24; i++) {
- e.key = data[i];
- /* data is just an integer, instead of a
+ e.key = data[i];
+ /* data is just an integer, instead of a
pointer to something */
e.data = (void *)i;
ep = hsearch(e, ENTER);