4 * Copyright (C) 1999-2001 Internet Software Consortium.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
11 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
17 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Id: msgcat.c,v 1.12 2001/11/30 01:59:39 gson Exp */
23 * Principal Author: Bob Halley
31 #include <isc/magic.h>
32 #include <isc/msgcat.h>
36 #include <nl_types.h> /* Required for nl_catd. */
40 * Implementation Notes:
42 * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
43 * because we don't want to require a memory context to be specified
44 * in order to use a message catalog.
54 #define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
55 #define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
58 isc_msgcat_open(const char *name
, isc_msgcat_t
**msgcatp
) {
62 * Open a message catalog.
65 REQUIRE(name
!= NULL
);
66 REQUIRE(msgcatp
!= NULL
&& *msgcatp
== NULL
);
68 msgcat
= malloc(sizeof(*msgcat
));
76 * We don't check if catopen() fails because we don't care.
77 * If it does fail, then when we call catgets(), it will use
80 msgcat
->catalog
= catopen(name
, 0);
82 msgcat
->magic
= MSGCAT_MAGIC
;
88 isc_msgcat_close(isc_msgcat_t
**msgcatp
) {
92 * Close a message catalog.
95 REQUIRE(msgcatp
!= NULL
);
97 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
101 if (msgcat
->catalog
!= (nl_catd
)(-1))
102 (void)catclose(msgcat
->catalog
);
112 isc_msgcat_get(isc_msgcat_t
*msgcat
, int set
, int message
,
113 const char *default_text
)
116 * Get message 'message' from message set 'set' in 'msgcat'. If it
117 * is not available, use 'default'.
120 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
122 REQUIRE(message
> 0);
123 REQUIRE(default_text
!= NULL
);
127 return (default_text
);
128 return (catgets(msgcat
->catalog
, set
, message
, default_text
));
130 return (default_text
);