No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / nvtable.c
blobc0a0e5bc3ff31ec54153e51b5a944f770ca72ddf
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* nvtable 3
6 /* SUMMARY
7 /* attribute list manager
8 /* SYNOPSIS
9 /* #include <nvtable.h>
11 /* typedef struct {
12 /* .in +4
13 /* char *key;
14 /* char *value;
15 /* /* private fields... */
16 /* .in -4
17 /* } NVTABLE_INFO;
19 /* NVTABLE *nvtable_create(size)
20 /* int size;
22 /* NVTABLE_INFO *nvtable_update(table, key, value)
23 /* NVTABLE *table;
24 /* const char *key;
25 /* const char *value;
27 /* char *nvtable_find(table, key)
28 /* NVTABLE *table;
29 /* const char *key;
31 /* NVTABLE_INFO *nvtable_locate(table, key)
32 /* NVTABLE *table;
33 /* const char *key;
35 /* void nvtable_delete(table, key)
36 /* NVTABLE *table;
37 /* const char *key;
39 /* void nvtable_free(table)
40 /* NVTABLE *table;
42 /* void nvtable_walk(table, action, ptr)
43 /* NVTABLE *table;
44 /* void (*action)(NVTABLE_INFO *, char *ptr);
45 /* char *ptr;
47 /* NVTABLE_INFO **nvtable_list(table)
48 /* NVTABLE *table;
49 /* DESCRIPTION
50 /* This module maintains one or more attribute lists. It provides a
51 /* more convenient interface than hash tables, although it uses the
52 /* same underlying implementation. Each attribute list entry consists
53 /* of a unique string-valued lookup key and a string value.
55 /* nvtable_create() creates a table of the specified size and returns a
56 /* pointer to the result.
58 /* nvtable_update() stores or updates a (key, value) pair in the specified
59 /* table and returns a pointer to the resulting entry. The key and the
60 /* value are copied.
62 /* nvtable_find() returns the value that was stored under the given key,
63 /* or a null pointer if it was not found. In order to distinguish
64 /* a null value from a non-existent value, use nvtable_locate().
66 /* nvtable_locate() returns a pointer to the entry that was stored
67 /* for the given key, or a null pointer if it was not found.
69 /* nvtable_delete() removes one entry that was stored under the given key.
71 /* nvtable_free() destroys a hash table, including contents.
73 /* nvtable_walk() invokes the action function for each table entry, with
74 /* a pointer to the entry as its argument. The ptr argument is passed
75 /* on to the action function.
77 /* nvtable_list() returns a null-terminated list of pointers to
78 /* all elements in the named table. The list should be passed to
79 /* myfree().
80 /* RESTRICTIONS
81 /* A callback function should not modify the attribute list that is
82 /* specified to its caller.
83 /* DIAGNOSTICS
84 /* The following conditions are reported and cause the program to
85 /* terminate immediately: memory allocation failure; an attempt
86 /* to delete a non-existent entry.
87 /* SEE ALSO
88 /* mymalloc(3) memory management wrapper
89 /* htable(3) hash table manager
90 /* LICENSE
91 /* .ad
92 /* .fi
93 /* The Secure Mailer license must be distributed with this software.
94 /* AUTHOR(S)
95 /* Wietse Venema
96 /* IBM T.J. Watson Research
97 /* P.O. Box 704
98 /* Yorktown Heights, NY 10598, USA
99 /*--*/
101 /* C library */
103 #include <sys_defs.h>
105 /* Utility library. */
107 #include <mymalloc.h>
108 #include <htable.h>
109 #include <nvtable.h>
111 /* nvtable_update - update or enter (key, value) pair */
113 NVTABLE_INFO *nvtable_update(NVTABLE * table, const char *key, const char *value)
115 NVTABLE_INFO *ht;
117 if ((ht = htable_locate(table, key)) != 0) {
118 myfree(ht->value);
119 } else {
120 ht = htable_enter(table, key, (char *) 0);
122 ht->value = mystrdup(value);
123 return (ht);