lib.c revision 302408
1219089Spjd/* 2219089Spjd * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3219089Spjd * Copyright (C) 1999-2001 Internet Software Consortium. 4219089Spjd * 5219089Spjd * Permission to use, copy, modify, and/or distribute this software for any 6219089Spjd * purpose with or without fee is hereby granted, provided that the above 7219089Spjd * copyright notice and this permission notice appear in all copies. 8219089Spjd * 9219089Spjd * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10219089Spjd * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11219089Spjd * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12219089Spjd * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13219089Spjd * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14219089Spjd * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15219089Spjd * PERFORMANCE OF THIS SOFTWARE. 16219089Spjd */ 17219089Spjd 18219089Spjd/* $Id: lib.c,v 1.16 2009/09/02 23:48:02 tbox Exp $ */ 19219089Spjd 20219089Spjd/*! \file */ 21219089Spjd 22219089Spjd#include <config.h> 23268657Sdelphij 24219089Spjd#include <stdio.h> 25219089Spjd#include <stdlib.h> 26219089Spjd 27219089Spjd#include <isc/app.h> 28219089Spjd#include <isc/lib.h> 29219089Spjd#include <isc/mem.h> 30219089Spjd#include <isc/msgs.h> 31219089Spjd#include <isc/once.h> 32219089Spjd#include <isc/socket.h> 33219089Spjd#include <isc/task.h> 34219089Spjd#include <isc/timer.h> 35219089Spjd#include <isc/util.h> 36219089Spjd 37219089Spjd/*** 38219089Spjd *** Globals 39219089Spjd ***/ 40219089Spjd 41219089SpjdLIBISC_EXTERNAL_DATA isc_msgcat_t * isc_msgcat = NULL; 42219089Spjd 43219089Spjd 44219089Spjd/*** 45219089Spjd *** Private 46219089Spjd ***/ 47219089Spjd 48219089Spjdstatic isc_once_t msgcat_once = ISC_ONCE_INIT; 49219089Spjd 50219089Spjd/*** 51219089Spjd *** Functions 52219089Spjd ***/ 53219089Spjd 54219089Spjdstatic void 55219089Spjdopen_msgcat(void) { 56219089Spjd isc_msgcat_open("libisc.cat", &isc_msgcat); 57219089Spjd} 58219089Spjd 59219089Spjdvoid 60219089Spjdisc_lib_initmsgcat(void) { 61219089Spjd isc_result_t result; 62219089Spjd 63219089Spjd /*! 64219089Spjd * Initialize the ISC library's message catalog, isc_msgcat, if it 65268657Sdelphij * has not already been initialized. 66219089Spjd */ 67219089Spjd 68219089Spjd result = isc_once_do(&msgcat_once, open_msgcat); 69219089Spjd if (result != ISC_R_SUCCESS) { 70219089Spjd /* 71219089Spjd * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but 72219089Spjd * we can't do that here, since they might call us! 73219089Spjd * (Note that the catalog might be open anyway, so we might 74219089Spjd * as well try to provide an internationalized message.) 75254112Sdelphij */ 76254112Sdelphij fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n", 77254112Sdelphij __FILE__, __LINE__, 78254112Sdelphij isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, 79254112Sdelphij ISC_MSG_FATALERROR, "fatal error"), 80254112Sdelphij isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, 81254112Sdelphij ISC_MSG_FAILED, "failed")); 82254112Sdelphij abort(); 83254112Sdelphij } 84254112Sdelphij} 85254112Sdelphij 86254112Sdelphij#ifndef BIND9 87254112Sdelphijstatic isc_once_t register_once = ISC_ONCE_INIT; 88254112Sdelphij 89254112Sdelphijstatic void 90254112Sdelphijdo_register(void) { 91254112Sdelphij RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS); 92254112Sdelphij RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS); 93254112Sdelphij RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS); 94254112Sdelphij RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS); 95254112Sdelphij RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS); 96254112Sdelphij} 97254112Sdelphij 98254112Sdelphijvoid 99254112Sdelphijisc_lib_register() { 100254112Sdelphij RUNTIME_CHECK(isc_once_do(®ister_once, do_register) 101254112Sdelphij == ISC_R_SUCCESS); 102254112Sdelphij} 103254112Sdelphij#endif 104254112Sdelphij