1258945Sroberto/*
2280849Scy * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
3258945Sroberto * Copyright (C) 1999-2001  Internet Software Consortium.
4258945Sroberto *
5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any
6258945Sroberto * purpose with or without fee is hereby granted, provided that the above
7258945Sroberto * copyright notice and this permission notice appear in all copies.
8258945Sroberto *
9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11258945Sroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15258945Sroberto * PERFORMANCE OF THIS SOFTWARE.
16258945Sroberto */
17258945Sroberto
18280849Scy/* $Id: lib.c,v 1.16 2009/09/02 23:48:02 tbox Exp $ */
19258945Sroberto
20258945Sroberto/*! \file */
21258945Sroberto
22258945Sroberto#include <config.h>
23258945Sroberto
24258945Sroberto#include <stdio.h>
25258945Sroberto#include <stdlib.h>
26258945Sroberto
27280849Scy#include <isc/app.h>
28280849Scy#include <isc/lib.h>
29280849Scy#include <isc/mem.h>
30280849Scy#include <isc/msgs.h>
31258945Sroberto#include <isc/once.h>
32280849Scy#include <isc/socket.h>
33280849Scy#include <isc/task.h>
34280849Scy#include <isc/timer.h>
35280849Scy#include <isc/util.h>
36258945Sroberto
37258945Sroberto/***
38258945Sroberto *** Globals
39258945Sroberto ***/
40258945Sroberto
41258945SrobertoLIBISC_EXTERNAL_DATA isc_msgcat_t *		isc_msgcat = NULL;
42258945Sroberto
43258945Sroberto
44258945Sroberto/***
45258945Sroberto *** Private
46258945Sroberto ***/
47258945Sroberto
48258945Srobertostatic isc_once_t		msgcat_once = ISC_ONCE_INIT;
49258945Sroberto
50258945Sroberto/***
51258945Sroberto *** Functions
52258945Sroberto ***/
53258945Sroberto
54258945Srobertostatic void
55258945Srobertoopen_msgcat(void) {
56258945Sroberto	isc_msgcat_open("libisc.cat", &isc_msgcat);
57258945Sroberto}
58258945Sroberto
59258945Srobertovoid
60258945Srobertoisc_lib_initmsgcat(void) {
61258945Sroberto	isc_result_t result;
62258945Sroberto
63258945Sroberto	/*!
64258945Sroberto	 * Initialize the ISC library's message catalog, isc_msgcat, if it
65258945Sroberto	 * has not already been initialized.
66258945Sroberto	 */
67258945Sroberto
68258945Sroberto	result = isc_once_do(&msgcat_once, open_msgcat);
69258945Sroberto	if (result != ISC_R_SUCCESS) {
70258945Sroberto		/*
71258945Sroberto		 * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
72258945Sroberto		 * we can't do that here, since they might call us!
73258945Sroberto		 * (Note that the catalog might be open anyway, so we might
74258945Sroberto		 * as well try to  provide an internationalized message.)
75258945Sroberto		 */
76258945Sroberto		fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
77258945Sroberto			__FILE__, __LINE__,
78258945Sroberto			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
79258945Sroberto				       ISC_MSG_FATALERROR, "fatal error"),
80258945Sroberto			isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
81258945Sroberto				       ISC_MSG_FAILED, "failed"));
82258945Sroberto		abort();
83258945Sroberto	}
84258945Sroberto}
85280849Scy
86280849Scy#ifndef BIND9
87280849Scystatic isc_once_t		register_once = ISC_ONCE_INIT;
88280849Scy
89280849Scystatic void
90280849Scydo_register(void) {
91280849Scy	RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS);
92280849Scy	RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS);
93280849Scy	RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS);
94280849Scy	RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS);
95280849Scy	RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS);
96280849Scy}
97280849Scy
98280849Scyvoid
99280849Scyisc_lib_register() {
100280849Scy	RUNTIME_CHECK(isc_once_do(&register_once, do_register)
101280849Scy		      == ISC_R_SUCCESS);
102280849Scy}
103280849Scy#endif
104