4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: msgcat.c,v 1.18 2007/06/19 23:47:18 tbox Exp */
24 * \author Principal Author: Bob Halley
32 #include <isc/magic.h>
33 #include <isc/msgcat.h>
37 #include <nl_types.h> /* Required for nl_catd. */
41 * Implementation Notes:
43 * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
44 * because we don't want to require a memory context to be specified
45 * in order to use a message catalog.
55 #define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
56 #define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
59 isc_msgcat_open(const char *name
, isc_msgcat_t
**msgcatp
) {
63 * Open a message catalog.
66 REQUIRE(name
!= NULL
);
67 REQUIRE(msgcatp
!= NULL
&& *msgcatp
== NULL
);
69 msgcat
= malloc(sizeof(*msgcat
));
77 * We don't check if catopen() fails because we don't care.
78 * If it does fail, then when we call catgets(), it will use
81 msgcat
->catalog
= catopen(name
, 0);
83 msgcat
->magic
= MSGCAT_MAGIC
;
89 isc_msgcat_close(isc_msgcat_t
**msgcatp
) {
93 * Close a message catalog.
96 REQUIRE(msgcatp
!= NULL
);
98 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
100 if (msgcat
!= NULL
) {
102 if (msgcat
->catalog
!= (nl_catd
)(-1))
103 (void)catclose(msgcat
->catalog
);
113 isc_msgcat_get(isc_msgcat_t
*msgcat
, int set
, int message
,
114 const char *default_text
)
117 * Get message 'message' from message set 'set' in 'msgcat'. If it
118 * is not available, use 'default'.
121 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
123 REQUIRE(message
> 0);
124 REQUIRE(default_text
!= NULL
);
128 return (default_text
);
129 return (catgets(msgcat
->catalog
, set
, message
, default_text
));
131 return (default_text
);