Path: blob/main/crypto/heimdal/lib/com_err/error.c
34870 views
/*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 <config.h>3536#include <stdio.h>37#include <stdlib.h>38#include <string.h>39#include <com_right.h>40#include <roken.h>4142#ifdef LIBINTL43#include <libintl.h>44#else45#define dgettext(d,s) (s)46#endif4748KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL49com_right(struct et_list *list, long code)50{51struct et_list *p;52for (p = list; p; p = p->next)53if (code >= p->table->base && code < p->table->base + p->table->n_msgs)54return p->table->msgs[code - p->table->base];55return NULL;56}5758KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL59com_right_r(struct et_list *list, long code, char *str, size_t len)60{61struct et_list *p;62for (p = list; p; p = p->next) {63if (code >= p->table->base && code < p->table->base + p->table->n_msgs) {64const char *msg = p->table->msgs[code - p->table->base];65#ifdef LIBINTL66char domain[12 + 20];67snprintf(domain, sizeof(domain), "heim_com_err%d", p->table->base);68#endif69strlcpy(str, dgettext(domain, msg), len);70return str;71}72}73return NULL;74}7576struct foobar {77struct et_list etl;78struct error_table et;79};8081KRB5_LIB_FUNCTION void KRB5_LIB_CALL82initialize_error_table_r(struct et_list **list,83const char **messages,84int num_errors,85long base)86{87struct et_list *et, **end;88struct foobar *f;89for (end = list, et = *list; et; end = &et->next, et = et->next)90if (et->table->msgs == messages)91return;92f = malloc(sizeof(*f));93if (f == NULL)94return;95et = &f->etl;96et->table = &f->et;97et->table->msgs = messages;98et->table->n_msgs = num_errors;99et->table->base = base;100et->next = NULL;101*end = et;102}103104105KRB5_LIB_FUNCTION void KRB5_LIB_CALL106free_error_table(struct et_list *et)107{108while(et){109struct et_list *p = et;110et = et->next;111free(p);112}113}114115116