#pragma weak _addsev = addsev
#include "lint.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;
if ((severity <= 4) || (severity > 255))
return (-1);
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)
return (0);
if (firstfree != -1)
i = firstfree;
else {
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);
}