usr/src/lib/libc/port/gen/addsev.c
author craigm
Tue, 15 Aug 2006 14:28:22 -0700
changeset 2552 04b007b7b43f
parent 0 68f95e015346
child 6812 febeba71273d
permissions -rw-r--r--
PSARC 2006/445 Generic 32-bit/64-bit symbolic links for ucblib libraries 1174853 Unknown external functions in 5.4 /usr/lib/libc.so: What is "glob"? 5084403 /usr/ucblib needs to ship with 32/64 symlinks

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/

#pragma	weak addsev = _addsev

#include "synonyms.h"
#include "mtlib.h"
#include "libc.h"
#include <stdlib.h>
#include <pfmt.h>
#include <thread.h>
#include "pfmt_data.h"
#include <sys/types.h>
#include <string.h>
#include <synch.h>

int
addsev(int severity, const char *string)
{
	int i, firstfree;
	void *new;

	/* Cannot redefine standard severity */
	if ((severity <= 4) || (severity > 255))
		return (-1);

	/* Locate severity in table */
	lrw_wrlock(&_rw_pfmt_sev_tab);
	for (i = 0, firstfree = -1; i < __pfmt_nsev; i++) {
		if (__pfmt_sev_tab[i].severity == 0 && firstfree == -1)
			firstfree = i;
		if (__pfmt_sev_tab[i].severity == severity)
			break;
	}

	if (i == __pfmt_nsev) {
		if (string == NULL)	/* Removing non-existing severity */
			return (0);
		if (firstfree != -1)	/* Re-use old entry */
			i = firstfree;
		else {
			/* Allocate new entry */
			new = libc_realloc(__pfmt_sev_tab,
			    sizeof (struct sev_tab) * (__pfmt_nsev + 1));
			if (new == NULL) {
				lrw_unlock(&_rw_pfmt_sev_tab);
				return (-1);
			}
			__pfmt_nsev++;
			__pfmt_sev_tab = new;
		}
	}
	if (string == NULL) {
		if (__pfmt_sev_tab[i].string)
			libc_free(__pfmt_sev_tab[i].string);
		__pfmt_sev_tab[i].severity = 0;
		__pfmt_sev_tab[i].string = NULL;
		lrw_unlock(&_rw_pfmt_sev_tab);
		return (0);
	}
	new = libc_realloc(__pfmt_sev_tab[i].string, strlen(string) + 1);
	if (new == NULL) {
		lrw_unlock(&_rw_pfmt_sev_tab);
		return (-1);
	}
	__pfmt_sev_tab[i].severity = severity;
	__pfmt_sev_tab[i].string = new;
	(void) strcpy(__pfmt_sev_tab[i].string, string);
	lrw_unlock(&_rw_pfmt_sev_tab);
	return (0);
}