lib.c revision ec5347e2c775f027573ce5648b910361aa926c01
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/*
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * Copyright (C) 1999-2001 Internet Software Consortium.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt *
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * Permission to use, copy, modify, and/or distribute this software for any
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * purpose with or without fee is hereby granted, provided that the above
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * copyright notice and this permission notice appear in all copies.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt *
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * PERFORMANCE OF THIS SOFTWARE.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/* $Id: lib.c,v 1.13 2007/06/18 23:47:44 tbox Exp $ */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/*! \file */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <config.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <stdio.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <stdlib.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <isc/once.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <isc/msgs.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#include <isc/lib.h>
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/***
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt *** Globals
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt ***/
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan HuntLIBISC_EXTERNAL_DATA isc_msgcat_t * isc_msgcat = NULL;
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/***
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt *** Private
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt ***/
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Huntstatic isc_once_t msgcat_once = ISC_ONCE_INIT;
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/***
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt *** Functions
e939674d53a127ddeeaf4b41fd72933f0b493308Mark Andrews ***/
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrewsstatic void
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrewsopen_msgcat(void) {
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews isc_msgcat_open("libisc.cat", &isc_msgcat);
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews}
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Huntvoid
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Huntisc_lib_initmsgcat(void) {
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Hunt isc_result_t result;
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews
ab598428c8bc10d75bb1ef5dff15f8848869cb1bMark Andrews /*!
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * Initialize the ISC library's message catalog, isc_msgcat, if it
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * has not already been initialized.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt */
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Hunt
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt result = isc_once_do(&msgcat_once, open_msgcat);
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt if (result != ISC_R_SUCCESS) {
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt /*
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * we can't do that here, since they might call us!
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * (Note that the catalog might be open anyway, so we might
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * as well try to provide an internationalized message.)
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt __FILE__, __LINE__,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt ISC_MSG_FATALERROR, "fatal error"),
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt ISC_MSG_FAILED, "failed"));
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt abort();
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt }
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt}
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt