10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2552Scraigm * Common Development and Distribution License (the "License"). 6*2552Scraigm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2552Scraigm * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 290Sstevel@tonic-gate /* All Rights Reserved */ 300Sstevel@tonic-gate 31*2552Scraigm #pragma weak addsev = _addsev 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include "synonyms.h" 340Sstevel@tonic-gate #include "mtlib.h" 350Sstevel@tonic-gate #include "libc.h" 360Sstevel@tonic-gate #include <stdlib.h> 370Sstevel@tonic-gate #include <pfmt.h> 380Sstevel@tonic-gate #include <thread.h> 390Sstevel@tonic-gate #include "pfmt_data.h" 400Sstevel@tonic-gate #include <sys/types.h> 410Sstevel@tonic-gate #include <string.h> 420Sstevel@tonic-gate #include <synch.h> 430Sstevel@tonic-gate 440Sstevel@tonic-gate int 450Sstevel@tonic-gate addsev(int severity, const char *string) 460Sstevel@tonic-gate { 470Sstevel@tonic-gate int i, firstfree; 480Sstevel@tonic-gate void *new; 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* Cannot redefine standard severity */ 510Sstevel@tonic-gate if ((severity <= 4) || (severity > 255)) 520Sstevel@tonic-gate return (-1); 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* Locate severity in table */ 550Sstevel@tonic-gate lrw_wrlock(&_rw_pfmt_sev_tab); 560Sstevel@tonic-gate for (i = 0, firstfree = -1; i < __pfmt_nsev; i++) { 570Sstevel@tonic-gate if (__pfmt_sev_tab[i].severity == 0 && firstfree == -1) 580Sstevel@tonic-gate firstfree = i; 590Sstevel@tonic-gate if (__pfmt_sev_tab[i].severity == severity) 600Sstevel@tonic-gate break; 610Sstevel@tonic-gate } 620Sstevel@tonic-gate 630Sstevel@tonic-gate if (i == __pfmt_nsev) { 640Sstevel@tonic-gate if (string == NULL) /* Removing non-existing severity */ 650Sstevel@tonic-gate return (0); 660Sstevel@tonic-gate if (firstfree != -1) /* Re-use old entry */ 670Sstevel@tonic-gate i = firstfree; 680Sstevel@tonic-gate else { 690Sstevel@tonic-gate /* Allocate new entry */ 700Sstevel@tonic-gate new = libc_realloc(__pfmt_sev_tab, 710Sstevel@tonic-gate sizeof (struct sev_tab) * (__pfmt_nsev + 1)); 720Sstevel@tonic-gate if (new == NULL) { 730Sstevel@tonic-gate lrw_unlock(&_rw_pfmt_sev_tab); 740Sstevel@tonic-gate return (-1); 750Sstevel@tonic-gate } 760Sstevel@tonic-gate __pfmt_nsev++; 770Sstevel@tonic-gate __pfmt_sev_tab = new; 780Sstevel@tonic-gate } 790Sstevel@tonic-gate } 800Sstevel@tonic-gate if (string == NULL) { 810Sstevel@tonic-gate if (__pfmt_sev_tab[i].string) 820Sstevel@tonic-gate libc_free(__pfmt_sev_tab[i].string); 830Sstevel@tonic-gate __pfmt_sev_tab[i].severity = 0; 840Sstevel@tonic-gate __pfmt_sev_tab[i].string = NULL; 850Sstevel@tonic-gate lrw_unlock(&_rw_pfmt_sev_tab); 860Sstevel@tonic-gate return (0); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate new = libc_realloc(__pfmt_sev_tab[i].string, strlen(string) + 1); 890Sstevel@tonic-gate if (new == NULL) { 900Sstevel@tonic-gate lrw_unlock(&_rw_pfmt_sev_tab); 910Sstevel@tonic-gate return (-1); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate __pfmt_sev_tab[i].severity = severity; 940Sstevel@tonic-gate __pfmt_sev_tab[i].string = new; 950Sstevel@tonic-gate (void) strcpy(__pfmt_sev_tab[i].string, string); 960Sstevel@tonic-gate lrw_unlock(&_rw_pfmt_sev_tab); 970Sstevel@tonic-gate return (0); 980Sstevel@tonic-gate } 99