xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/dict_static.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: dict_static.c,v 1.1.1.2 2013/01/02 18:59:12 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	dict_static 3
6 /* SUMMARY
7 /*	dictionary manager interface to static variables
8 /* SYNOPSIS
9 /*	#include <dict_static.h>
10 /*
11 /*	DICT	*dict_static_open(name, name, dict_flags)
12 /*	const char *name;
13 /*	int	dummy;
14 /*	int	dict_flags;
15 /* DESCRIPTION
16 /*	dict_static_open() implements a dummy dictionary that returns
17 /*	as lookup result the dictionary name, regardless of the lookup
18 /*	key value.
19 /* SEE ALSO
20 /*	dict(3) generic dictionary manager
21 /* LICENSE
22 /* .ad
23 /* .fi
24 /*	The Secure Mailer license must be distributed with this software.
25 /* AUTHOR(S)
26 /*	jeffm
27 /*	ghostgun.com
28 /*--*/
29 
30 /* System library. */
31 
32 #include "sys_defs.h"
33 #include <stdio.h>			/* sprintf() prototype */
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <string.h>
37 
38 /* Utility library. */
39 
40 #include "mymalloc.h"
41 #include "msg.h"
42 #include "dict.h"
43 #include "dict_static.h"
44 
45 /* dict_static_lookup - access static value*/
46 
47 static const char *dict_static_lookup(DICT *dict, const char *unused_name)
48 {
49     DICT_ERR_VAL_RETURN(dict, DICT_ERR_NONE, dict->name);
50 }
51 
52 /* dict_static_close - close static dictionary */
53 
54 static void dict_static_close(DICT *dict)
55 {
56     dict_free(dict);
57 }
58 
59 /* dict_static_open - make association with static variable */
60 
61 DICT   *dict_static_open(const char *name, int unused_flags, int dict_flags)
62 {
63     DICT   *dict;
64 
65     dict = dict_alloc(DICT_TYPE_STATIC, name, sizeof(*dict));
66     dict->lookup = dict_static_lookup;
67     dict->close = dict_static_close;
68     dict->flags = dict_flags | DICT_FLAG_FIXED;
69     dict->owner.status = DICT_OWNER_TRUSTED;
70     return (DICT_DEBUG (dict));
71 }
72