/* */
This source file includes following definitions.
- assoc_open
- assoc_close
- assoc_put
- assoc_put_withlen
- assoc_get
1 /*
2 * Copyright (c) 2004, 2010 Tama Communications Corporation
3 *
4 * This file is part of GNU GLOBAL.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22 #ifdef STDC_HEADERS
23 #include <stdlib.h>
24 #endif
25
26 #include "checkalloc.h"
27 #include "die.h"
28 #include "assoc.h"
29
30 /**
31 * assoc_open: open associate array.
32 *
33 * @return descriptor
34 */
35 ASSOC *
36 assoc_open(void)
37 {
38 ASSOC *assoc = (ASSOC *)check_malloc(sizeof(ASSOC));
39
40 /*
41 * Use invisible temporary file.
42 */
43 assoc->dbop = dbop_open(NULL, 1, 0600, 0);
44 if (assoc->dbop == NULL)
45 abort();
46 assoc->dbop->put_errmsg = "cannot write to temporary file.\nYou can specify the directory for the temporary file using environment variable 'TMPDIR'.";
47 return assoc;
48 }
49 /**
50 * assoc_close: close associate array.
51 *
52 * @param[in] assoc descriptor
53 */
54 void
55 assoc_close(ASSOC *assoc)
56 {
57 if (assoc == NULL)
58 return;
59 if (assoc->dbop == NULL)
60 abort();
61 dbop_close(assoc->dbop);
62 free(assoc);
63 }
64 /**
65 * assoc_put: put data into associate array.
66 *
67 * @param[in] assoc descriptor
68 * @param[in] name name
69 * @param[in] value value
70 */
71 void
72 assoc_put(ASSOC *assoc, const char *name, const char *value)
73 {
74 if (assoc->dbop == NULL)
75 abort();
76 dbop_put(assoc->dbop, name, value);
77 }
78 /**
79 * assoc_put_withlen: put data into associate array.
80 *
81 * @param[in] assoc descriptor
82 * @param[in] name name
83 * @param[in] value value
84 * @param[in] len length
85 */
86 void
87 assoc_put_withlen(ASSOC *assoc, const char *name, const char *value, int len)
88 {
89 if (assoc->dbop == NULL)
90 abort();
91 dbop_put_withlen(assoc->dbop, name, value, len);
92 }
93 /**
94 * assoc_get: get data from associate array.
95 *
96 * @param[in] assoc descriptor
97 * @param[in] name name
98 * @return value
99 */
100 const char *
101 assoc_get(ASSOC *assoc, const char *name)
102 {
103 if (assoc->dbop == NULL)
104 abort();
105 return dbop_get(assoc->dbop, name);
106 }
/* */