2 * Copyright (C) 1999-2001 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: msgcat.c,v 1.12 2001/11/30 01:59:39 gson Exp $ */
21 * Principal Author: Bob Halley
29 #include <isc/magic.h>
30 #include <isc/msgcat.h>
34 #include <nl_types.h> /* Required for nl_catd. */
38 * Implementation Notes:
40 * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
41 * because we don't want to require a memory context to be specified
42 * in order to use a message catalog.
52 #define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
53 #define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
56 isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp) {
60 * Open a message catalog.
63 REQUIRE(name != NULL);
64 REQUIRE(msgcatp != NULL && *msgcatp == NULL);
66 msgcat = malloc(sizeof(*msgcat));
74 * We don't check if catopen() fails because we don't care.
75 * If it does fail, then when we call catgets(), it will use
78 msgcat->catalog = catopen(name, 0);
80 msgcat->magic = MSGCAT_MAGIC;
86 isc_msgcat_close(isc_msgcat_t **msgcatp) {
90 * Close a message catalog.
93 REQUIRE(msgcatp != NULL);
95 REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
99 if (msgcat->catalog != (nl_catd)(-1))
100 (void)catclose(msgcat->catalog);
110 isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message,
111 const char *default_text)
114 * Get message 'message' from message set 'set' in 'msgcat'. If it
115 * is not available, use 'default'.
118 REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
120 REQUIRE(message > 0);
121 REQUIRE(default_text != NULL);
125 return (default_text);
126 return (catgets(msgcat->catalog, set, message, default_text));
128 return (default_text);