2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: msgcat.c,v 1.13.18.3 2005/06/08 02:07:57 marka Exp $ */
22 * \author Principal Author: Bob Halley
30 #include <isc/magic.h>
31 #include <isc/msgcat.h>
35 #include <nl_types.h> /* Required for nl_catd. */
39 * Implementation Notes:
41 * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
42 * because we don't want to require a memory context to be specified
43 * in order to use a message catalog.
53 #define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
54 #define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
57 isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp) {
61 * Open a message catalog.
64 REQUIRE(name != NULL);
65 REQUIRE(msgcatp != NULL && *msgcatp == NULL);
67 msgcat = malloc(sizeof(*msgcat));
75 * We don't check if catopen() fails because we don't care.
76 * If it does fail, then when we call catgets(), it will use
79 msgcat->catalog = catopen(name, 0);
81 msgcat->magic = MSGCAT_MAGIC;
87 isc_msgcat_close(isc_msgcat_t **msgcatp) {
91 * Close a message catalog.
94 REQUIRE(msgcatp != NULL);
96 REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
100 if (msgcat->catalog != (nl_catd)(-1))
101 (void)catclose(msgcat->catalog);
111 isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message,
112 const char *default_text)
115 * Get message 'message' from message set 'set' in 'msgcat'. If it
116 * is not available, use 'default'.
119 REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
121 REQUIRE(message > 0);
122 REQUIRE(default_text != NULL);
126 return (default_text);
127 return (catgets(msgcat->catalog, set, message, default_text));
129 return (default_text);