2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "libuutil_common.h"
2N/A
2N/A#include <errno.h>
2N/A#include <libintl.h>
2N/A#include <stdarg.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <strings.h>
2N/A
2N/A#define FACILITY_FMT "%s (%s): "
2N/A
2N/A#if !defined(TEXT_DOMAIN)
2N/A#define TEXT_DOMAIN "SYS_TEST"
2N/A#endif
2N/A
2N/Astatic const char *
2N/Astrseverity(uu_dprintf_severity_t severity)
2N/A{
2N/A switch (severity) {
2N/A case UU_DPRINTF_SILENT:
2N/A return (dgettext(TEXT_DOMAIN, "silent"));
2N/A case UU_DPRINTF_FATAL:
2N/A return (dgettext(TEXT_DOMAIN, "FATAL"));
2N/A case UU_DPRINTF_WARNING:
2N/A return (dgettext(TEXT_DOMAIN, "WARNING"));
2N/A case UU_DPRINTF_NOTICE:
2N/A return (dgettext(TEXT_DOMAIN, "note"));
2N/A case UU_DPRINTF_INFO:
2N/A return (dgettext(TEXT_DOMAIN, "info"));
2N/A case UU_DPRINTF_DEBUG:
2N/A return (dgettext(TEXT_DOMAIN, "debug"));
2N/A default:
2N/A return (dgettext(TEXT_DOMAIN, "unspecified"));
2N/A }
2N/A}
2N/A
2N/Auu_dprintf_t *
2N/Auu_dprintf_create(const char *name, uu_dprintf_severity_t severity,
2N/A uint_t flags)
2N/A{
2N/A uu_dprintf_t *D;
2N/A
2N/A if (uu_check_name(name, UU_NAME_DOMAIN) == -1) {
2N/A uu_set_error(UU_ERROR_INVALID_ARGUMENT);
2N/A return (NULL);
2N/A }
2N/A
2N/A if ((D = uu_zalloc(sizeof (uu_dprintf_t))) == NULL)
2N/A return (NULL);
2N/A
2N/A if (name != NULL) {
2N/A D->uud_name = strdup(name);
2N/A if (D->uud_name == NULL) {
2N/A uu_free(D);
2N/A return (NULL);
2N/A }
2N/A } else {
2N/A D->uud_name = NULL;
2N/A }
2N/A
2N/A D->uud_severity = severity;
2N/A D->uud_flags = flags;
2N/A
2N/A return (D);
2N/A}
2N/A
2N/A/*PRINTFLIKE3*/
2N/Avoid
2N/Auu_dprintf(uu_dprintf_t *D, uu_dprintf_severity_t severity,
2N/A const char *format, ...)
2N/A{
2N/A va_list alist;
2N/A
2N/A /* XXX Assert that severity is not UU_DPRINTF_SILENT. */
2N/A
2N/A if (severity > D->uud_severity)
2N/A return;
2N/A
2N/A (void) fprintf(stderr, FACILITY_FMT, D->uud_name,
2N/A strseverity(severity));
2N/A
2N/A va_start(alist, format);
2N/A (void) vfprintf(stderr, format, alist);
2N/A va_end(alist);
2N/A}
2N/A
2N/Avoid
2N/Auu_dprintf_destroy(uu_dprintf_t *D)
2N/A{
2N/A if (D->uud_name)
2N/A free(D->uud_name);
2N/A
2N/A uu_free(D);
2N/A}
2N/A
2N/Aconst char *
2N/Auu_dprintf_getname(uu_dprintf_t *D)
2N/A{
2N/A return (D->uud_name);
2N/A}