1/*	$NetBSD: lib.c,v 1.1.1.1 2009/12/13 16:54:19 kardel Exp $	*/
2
3/*
4 * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001  Internet Software Consortium.
6 *
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.
10 *
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.
18 */
19
20/* Id: lib.c,v 1.14 2007/06/19 23:47:17 tbox Exp */
21
22/*! \file */
23
24#include <config.h>
25
26#include <stdio.h>
27#include <stdlib.h>
28
29#include <isc/once.h>
30#include <isc/msgs.h>
31#include <isc/lib.h>
32
33/***
34 *** Globals
35 ***/
36
37LIBISC_EXTERNAL_DATA isc_msgcat_t *		isc_msgcat = NULL;
38
39
40/***
41 *** Private
42 ***/
43
44static isc_once_t		msgcat_once = ISC_ONCE_INIT;
45
46
47/***
48 *** Functions
49 ***/
50
51static void
52open_msgcat(void) {
53	isc_msgcat_open("libisc.cat", &isc_msgcat);
54}
55
56void
57isc_lib_initmsgcat(void) {
58	isc_result_t result;
59
60	/*!
61	 * Initialize the ISC library's message catalog, isc_msgcat, if it
62	 * has not already been initialized.
63	 */
64
65	result = isc_once_do(&msgcat_once, open_msgcat);
66	if (result != ISC_R_SUCCESS) {
67		/*
68		 * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
69		 * we can't do that here, since they might call us!
70		 * (Note that the catalog might be open anyway, so we might
71		 * as well try to  provide an internationalized message.)
72		 */
73		fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
74			__FILE__, __LINE__,
75			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
76				       ISC_MSG_FATALERROR, "fatal error"),
77			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
78				       ISC_MSG_FAILED, "failed"));
79		abort();
80	}
81}
82