2 * Copyright (C) 2004 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.10.2.1 2004/03/09 06:12:04 marka Exp $ */
21 * Principal Author: Bob Halley
28 #include <isc/magic.h>
29 #include <isc/msgcat.h>
33 #include <nl_types.h> /* Required for nl_catd. */
37 * Implementation Notes:
39 * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
40 * because we don't want to require a memory context to be specified
41 * in order to use a message catalog.
51 #define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
52 #define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
55 isc_msgcat_open(const char *name
, isc_msgcat_t
**msgcatp
) {
59 * Open a message catalog.
62 REQUIRE(name
!= NULL
);
63 REQUIRE(msgcatp
!= NULL
&& *msgcatp
== NULL
);
65 msgcat
= malloc(sizeof *msgcat
);
73 * We don't check if catopen() fails because we don't care.
74 * If it does fail, then when we call catgets(), it will use
77 msgcat
->catalog
= catopen(name
, 0);
79 msgcat
->magic
= MSGCAT_MAGIC
;
85 isc_msgcat_close(isc_msgcat_t
**msgcatp
) {
89 * Close a message catalog.
92 REQUIRE(msgcatp
!= NULL
);
94 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
98 if (msgcat
->catalog
!= (nl_catd
)(-1))
99 catclose(msgcat
->catalog
);
109 isc_msgcat_get(isc_msgcat_t
*msgcat
, int set
, int message
,
110 const char *default_text
)
113 * Get message 'message' from message set 'set' in 'msgcat'. If it
114 * is not available, use 'default'.
117 REQUIRE(VALID_MSGCAT(msgcat
) || msgcat
== NULL
);
119 REQUIRE(message
> 0);
120 REQUIRE(default_text
!= NULL
);
124 return (default_text
);
125 return (catgets(msgcat
->catalog
, set
, message
, default_text
));
127 return (default_text
);