4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #pragma weak _addsev = addsev
40 #include "pfmt_data.h"
41 #include <sys/types.h>
46 addsev(int severity
, const char *string
)
51 /* Cannot redefine standard severity */
52 if ((severity
<= 4) || (severity
> 255))
55 /* Locate severity in table */
56 lrw_wrlock(&_rw_pfmt_sev_tab
);
57 for (i
= 0, firstfree
= -1; i
< __pfmt_nsev
; i
++) {
58 if (__pfmt_sev_tab
[i
].severity
== 0 && firstfree
== -1)
60 if (__pfmt_sev_tab
[i
].severity
== severity
)
64 if (i
== __pfmt_nsev
) {
65 if (string
== NULL
) /* Removing non-existing severity */
67 if (firstfree
!= -1) /* Re-use old entry */
70 /* Allocate new entry */
71 new = libc_realloc(__pfmt_sev_tab
,
72 sizeof (struct sev_tab
) * (__pfmt_nsev
+ 1));
74 lrw_unlock(&_rw_pfmt_sev_tab
);
82 if (__pfmt_sev_tab
[i
].string
)
83 libc_free(__pfmt_sev_tab
[i
].string
);
84 __pfmt_sev_tab
[i
].severity
= 0;
85 __pfmt_sev_tab
[i
].string
= NULL
;
86 lrw_unlock(&_rw_pfmt_sev_tab
);
89 new = libc_realloc(__pfmt_sev_tab
[i
].string
, strlen(string
) + 1);
91 lrw_unlock(&_rw_pfmt_sev_tab
);
94 __pfmt_sev_tab
[i
].severity
= severity
;
95 __pfmt_sev_tab
[i
].string
= new;
96 (void) strcpy(__pfmt_sev_tab
[i
].string
, string
);
97 lrw_unlock(&_rw_pfmt_sev_tab
);