diff options
| author | christos <christos@NetBSD.org> | 2014-07-20 20:17:21 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2014-07-20 20:17:21 +0000 |
| commit | c80dfef2b1aae6f50bc152fcd160181f5d6d75ba (patch) | |
| tree | 029355bb9d5c197ba06be6198576c8c36fce97dd /lib/libc/stdlib | |
| parent | cfd7b574b2ab2665ab88f30175c7d8e18a1baaa3 (diff) | |
amend the new destroy function to take function pointers.
Diffstat (limited to 'lib/libc/stdlib')
| -rw-r--r-- | lib/libc/stdlib/hcreate.3 | 32 | ||||
| -rw-r--r-- | lib/libc/stdlib/hcreate.c | 23 |
2 files changed, 26 insertions, 29 deletions
diff --git a/lib/libc/stdlib/hcreate.3 b/lib/libc/stdlib/hcreate.3 index 10eb974d818..129a282b63d 100644 --- a/lib/libc/stdlib/hcreate.3 +++ b/lib/libc/stdlib/hcreate.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: hcreate.3,v 1.12 2014/07/20 13:41:14 wiz Exp $ +.\" $NetBSD: hcreate.3,v 1.13 2014/07/20 20:17:21 christos Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -51,11 +51,11 @@ .Ft void .Fn hdestroy "void" .Ft void -.Fn hdestroy1 "int flags" +.Fn hdestroy1 "void (*freekey)(void *)" "void (*freedata)(void *)" .Ft void .Fn hdestroy_r "struct hsearch_data *table" .Ft void -.Fn hdestroy1_r "struct hsearch_data *table" "int flags" +.Fn hdestroy1_r "struct hsearch_data *table" "void (*freekey)(void *)" "void (*freedata)(void *)" .Ft ENTRY * .Fn hsearch "ENTRY item" "ACTION action" .Ft int @@ -166,27 +166,23 @@ function provided, the .Fn hdestroy1 and .Fn hdestroy1_r -allow controlling if the +allow controlling how the .Fa key or .Fa value will be freed using the -.Fa flags -argument. -If the bit -.Dv FREE_KEY -is set, then the +provided functions in the +.Fa freekey +and +.Fa freedata +arguments. +If they are +.Dv NULL , +then .Fa key -of each entry will be -passed to -.Xr free 3 . -If the bit -.Dv FREE_VALUE -is set, then the +and .Fa value -of each entry will be -passed to -.Xr free 3 . +are not freed. .Pp The .Fn hcreate_r , diff --git a/lib/libc/stdlib/hcreate.c b/lib/libc/stdlib/hcreate.c index 53e4abd157a..cab145d13b7 100644 --- a/lib/libc/stdlib/hcreate.c +++ b/lib/libc/stdlib/hcreate.c @@ -1,4 +1,4 @@ -/* $NetBSD: hcreate.c,v 1.9 2014/07/20 13:34:17 christos Exp $ */ +/* $NetBSD: hcreate.c,v 1.10 2014/07/20 20:17:21 christos Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -43,7 +43,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: hcreate.c,v 1.9 2014/07/20 13:34:17 christos Exp $"); +__RCSID("$NetBSD: hcreate.c,v 1.10 2014/07/20 20:17:21 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #if !defined(lint) @@ -141,20 +141,21 @@ hcreate_r(size_t nel, struct hsearch_data *head) } void -hdestroy1(int flags) +hdestroy1(void (*freekey)(void *), void (*freedata)(void *)) { _DIAGASSERT(htable.table != NULL); - hdestroy1_r(&htable, flags); + hdestroy1_r(&htable, freekey, freedata); } void hdestroy(void) { - hdestroy1(0); + hdestroy1(NULL, NULL); } void -hdestroy1_r(struct hsearch_data *head, int flags) +hdestroy1_r(struct hsearch_data *head, void (*freekey)(void *), + void (*freedata)(void *)) { struct internal_entry *ie; size_t idx; @@ -172,10 +173,10 @@ hdestroy1_r(struct hsearch_data *head, int flags) while (!SLIST_EMPTY(&table[idx])) { ie = SLIST_FIRST(&table[idx]); SLIST_REMOVE_HEAD(&table[idx], link); - if (flags & FREE_KEY) - free(ie->ent.key); - if (flags & FREE_DATA) - free(ie->ent.data); + if (freekey) + (*freekey)(ie->ent.key); + if (freedata) + (*freedata)(ie->ent.data); free(ie); } } @@ -185,7 +186,7 @@ hdestroy1_r(struct hsearch_data *head, int flags) void hdestroy_r(struct hsearch_data *head) { - hdestroy1_r(head, 0); + hdestroy1_r(head, NULL, NULL); } ENTRY * |
