Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / dict_alloc.c
blob58305e1d43c8cc16381e4e7e021e33521186f4fd
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* dict_alloc 3
6 /* SUMMARY
7 /* dictionary memory manager
8 /* SYNOPSIS
9 /* #include <dict.h>
11 /* DICT *dict_alloc(dict_type, dict_name, size)
12 /* const char *dict_type;
13 /* const char *dict_name;
14 /* ssize_t size;
16 /* void dict_free(dict)
17 /* DICT *ptr;
18 /* DESCRIPTION
19 /* dict_alloc() allocates memory for a dictionary structure of
20 /* \fIsize\fR bytes, initializes all generic dictionary
21 /* properties to default settings,
22 /* and installs default methods that do not support any operation.
23 /* The caller is supposed to override the default methods with
24 /* ones that it supports.
25 /* The purpose of the default methods is to trap an attempt to
26 /* invoke an unsupported method.
28 /* dict_free() releases memory and cleans up after dict_alloc().
29 /* It is up to the caller to dispose of any memory that was allocated
30 /* by the caller.
32 /* Arguments:
33 /* .IP dict_type
34 /* The official name for this type of dictionary, as used by
35 /* dict_open(3) etc. This is stored under the \fBtype\fR
36 /* member.
37 /* .IP dict_name
38 /* Dictionary name. This is stored as the \fBname\fR member.
39 /* .IP size
40 /* The size in bytes of the dictionary subclass structure instance.
41 /* SEE ALSO
42 /* dict(3)
43 /* DIAGNOSTICS
44 /* Fatal errors: the process invokes a default method.
45 /* LICENSE
46 /* .ad
47 /* .fi
48 /* The Secure Mailer license must be distributed with this software.
49 /* AUTHOR(S)
50 /* Wietse Venema
51 /* IBM T.J. Watson Research
52 /* P.O. Box 704
53 /* Yorktown Heights, NY 10598, USA
54 /*--*/
56 /* System libraries. */
58 #include "sys_defs.h"
60 /* Utility library. */
62 #include "msg.h"
63 #include "mymalloc.h"
64 #include "dict.h"
66 /* dict_default_lookup - trap unimplemented operation */
68 static const char *dict_default_lookup(DICT *dict, const char *unused_key)
70 msg_fatal("%s table %s: lookup operation is not supported",
71 dict->type, dict->name);
74 /* dict_default_update - trap unimplemented operation */
76 static void dict_default_update(DICT *dict, const char *unused_key,
77 const char *unused_value)
79 msg_fatal("%s table %s: update operation is not supported",
80 dict->type, dict->name);
83 /* dict_default_delete - trap unimplemented operation */
85 static int dict_default_delete(DICT *dict, const char *unused_key)
87 msg_fatal("%s table %s: delete operation is not supported",
88 dict->type, dict->name);
91 /* dict_default_sequence - trap unimplemented operation */
93 static int dict_default_sequence(DICT *dict, int unused_function,
94 const char **unused_key, const char **unused_value)
96 msg_fatal("%s table %s: sequence operation is not supported",
97 dict->type, dict->name);
100 /* dict_default_close - trap unimplemented operation */
102 static void dict_default_close(DICT *dict)
104 msg_fatal("%s table %s: close operation is not supported",
105 dict->type, dict->name);
108 /* dict_alloc - allocate dictionary object, initialize super-class */
110 DICT *dict_alloc(const char *dict_type, const char *dict_name, ssize_t size)
112 DICT *dict = (DICT *) mymalloc(size);
114 dict->type = mystrdup(dict_type);
115 dict->name = mystrdup(dict_name);
116 dict->flags = DICT_FLAG_FIXED;
117 dict->lookup = dict_default_lookup;
118 dict->update = dict_default_update;
119 dict->delete = dict_default_delete;
120 dict->sequence = dict_default_sequence;
121 dict->close = dict_default_close;
122 dict->lock_fd = -1;
123 dict->stat_fd = -1;
124 dict->mtime = 0;
125 dict->fold_buf = 0;
126 return dict;
129 /* dict_free - super-class destructor */
131 void dict_free(DICT *dict)
133 myfree(dict->type);
134 myfree(dict->name);
135 myfree((char *) dict);