/*1* Copyright (c) 1997, 1998, 2001 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/323334#include <stdio.h>35#include <stdlib.h>36#include <string.h>37#include <com_right.h>3839#ifdef LIBINTL40#include <libintl.h>41#else42#define dgettext(d,s) (s)43#endif4445KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL46com_right(struct et_list *list, long code)47{48struct et_list *p;49for (p = list; p; p = p->next)50if (code >= p->table->base && code < p->table->base + p->table->n_msgs)51return p->table->msgs[code - p->table->base];52return NULL;53}5455KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL56com_right_r(struct et_list *list, long code, char *str, size_t len)57{58struct et_list *p;59for (p = list; p; p = p->next) {60if (code >= p->table->base && code < p->table->base + p->table->n_msgs) {61const char *msg = p->table->msgs[code - p->table->base];62#ifdef LIBINTL63char domain[12 + 20];64snprintf(domain, sizeof(domain), "heim_com_err%d", p->table->base);65#endif66strlcpy(str, dgettext(domain, msg), len);67return str;68}69}70return NULL;71}7273struct foobar {74struct et_list etl;75struct error_table et;76};7778KRB5_LIB_FUNCTION void KRB5_LIB_CALL79initialize_error_table_r(struct et_list **list,80const char **messages,81int num_errors,82long base)83{84struct et_list *et, **end;85struct foobar *f;86for (end = list, et = *list; et; end = &et->next, et = et->next)87if (et->table->msgs == messages)88return;89f = malloc(sizeof(*f));90if (f == NULL)91return;92et = &f->etl;93et->table = &f->et;94et->table->msgs = messages;95et->table->n_msgs = num_errors;96et->table->base = base;97et->next = NULL;98*end = et;99}100101102KRB5_LIB_FUNCTION void KRB5_LIB_CALL103free_error_table(struct et_list *et)104{105while(et){106struct et_list *p = et;107et = et->next;108free(p);109}110}111112113