util.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
* 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 (c) 1997-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* util.c -- low-level utilities used by map*.c
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include "xlator.h"
#include "util.h"
#include "errlog.h"
/*
* String tables -- WARNING! This uses realloc to recreate tables,
* so always assign table_t * return value to the current
* table pointer, lest the table address change in the
* called function.
*/
static char *strset(char *, char *);
table_t *
create_stringtable(int size)
{
table_t *t;
/* Solaris idiom: malloc && memset. TBD. */
"\nOut of memory.\n"
"We wish to hold the whole sky,\n"
"But we never will.\n");
}
t->used = -1;
return (t);
}
table_t *
{
int i;
if (t == NULL) {
"a NULL table");
}
if (in_stringtable(t, value)) {
return (t);
}
++t->used;
((sizeof (char *)) * (t->nelem + TABLE_INCREMENT)))))
== NULL) {
"string table");
}
t = t2;
t->nelem += TABLE_INCREMENT;
}
}
return (t);
}
/*
* free_stringtable -- really only mark it empty for reuse.
*/
table_t *
{
if (t != NULL) {
t->used = -1;
}
return (t);
}
char *
{
if (t == NULL) {
return (NULL);
return (NULL);
} else {
}
}
int
{
int i;
if (t == NULL) {
return (0);
}
for (i = 0; i <= t->used; ++i) {
return (1);
}
return (0);
}
void
{
int i;
if (t == NULL)
return;
"table size = %d elements out of %d elements/%d bytes\n",
for (i = 0; i <= t->used; ++i) {
get_stringtable(t, i));
}
}
static int
compare(const void *p, const void *q)
{
return (strcmp((char *)p, (char *)q));
}
void
{
if (t && t->used > 0) {
sizeof (char *), compare);
}
}
/*
* strset -- update a dynamically-allocated string or die trying.
*/
/*ARGSUSED*/
static char *
{
/* It was never allocated, so allocate it. */
"string");
}
/* Reallocate bigger. */
"a string");
}
}
return (string);
}