150764Smarkm/* 2233294Sstas * Copyright (c) 1997, 1998, 2001 Kungliga Tekniska H��gskolan 3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4233294Sstas * All rights reserved. 550764Smarkm * 6233294Sstas * Redistribution and use in source and binary forms, with or without 7233294Sstas * modification, are permitted provided that the following conditions 8233294Sstas * are met: 950764Smarkm * 10233294Sstas * 1. Redistributions of source code must retain the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer. 1250764Smarkm * 13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 14233294Sstas * notice, this list of conditions and the following disclaimer in the 15233294Sstas * documentation and/or other materials provided with the distribution. 1650764Smarkm * 17233294Sstas * 3. Neither the name of the Institute nor the names of its contributors 18233294Sstas * may be used to endorse or promote products derived from this software 19233294Sstas * without specific prior written permission. 2050764Smarkm * 21233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31233294Sstas * SUCH DAMAGE. 3250764Smarkm */ 3350764Smarkm 34233294Sstas 3550764Smarkm#include <stdio.h> 3650764Smarkm#include <stdlib.h> 3750764Smarkm#include <string.h> 3850764Smarkm#include <com_right.h> 3950764Smarkm 40233294Sstas#ifdef LIBINTL 41233294Sstas#include <libintl.h> 42233294Sstas#else 43233294Sstas#define dgettext(d,s) (s) 44233294Sstas#endif 45233294Sstas 46233294SstasKRB5_LIB_FUNCTION const char * KRB5_LIB_CALL 4750764Smarkmcom_right(struct et_list *list, long code) 4850764Smarkm{ 4950764Smarkm struct et_list *p; 50233294Sstas for (p = list; p; p = p->next) 5150764Smarkm if (code >= p->table->base && code < p->table->base + p->table->n_msgs) 5250764Smarkm return p->table->msgs[code - p->table->base]; 53233294Sstas return NULL; 54233294Sstas} 55233294Sstas 56233294SstasKRB5_LIB_FUNCTION const char * KRB5_LIB_CALL 57233294Sstascom_right_r(struct et_list *list, long code, char *str, size_t len) 58233294Sstas{ 59233294Sstas struct et_list *p; 60233294Sstas for (p = list; p; p = p->next) { 61233294Sstas if (code >= p->table->base && code < p->table->base + p->table->n_msgs) { 62233294Sstas const char *msg = p->table->msgs[code - p->table->base]; 63233294Sstas#ifdef LIBINTL 64233294Sstas char domain[12 + 20]; 65233294Sstas snprintf(domain, sizeof(domain), "heim_com_err%d", p->table->base); 66233294Sstas#endif 67233294Sstas strlcpy(str, dgettext(domain, msg), len); 68233294Sstas return str; 69233294Sstas } 7050764Smarkm } 7150764Smarkm return NULL; 7250764Smarkm} 7350764Smarkm 7450764Smarkmstruct foobar { 7550764Smarkm struct et_list etl; 7650764Smarkm struct error_table et; 7750764Smarkm}; 7850764Smarkm 79233294SstasKRB5_LIB_FUNCTION void KRB5_LIB_CALL 80233294Sstasinitialize_error_table_r(struct et_list **list, 81233294Sstas const char **messages, 8250764Smarkm int num_errors, 8350764Smarkm long base) 8450764Smarkm{ 85127804Snectar struct et_list *et, **end; 8650764Smarkm struct foobar *f; 87127804Snectar for (end = list, et = *list; et; end = &et->next, et = et->next) 8850764Smarkm if (et->table->msgs == messages) 8950764Smarkm return; 9050764Smarkm f = malloc(sizeof(*f)); 9150764Smarkm if (f == NULL) 9250764Smarkm return; 9350764Smarkm et = &f->etl; 9450764Smarkm et->table = &f->et; 9550764Smarkm et->table->msgs = messages; 9650764Smarkm et->table->n_msgs = num_errors; 9750764Smarkm et->table->base = base; 98127804Snectar et->next = NULL; 99127804Snectar *end = et; 10050764Smarkm} 10150764Smarkm 102233294Sstas 103233294SstasKRB5_LIB_FUNCTION void KRB5_LIB_CALL 10450764Smarkmfree_error_table(struct et_list *et) 10550764Smarkm{ 10650764Smarkm while(et){ 10750764Smarkm struct et_list *p = et; 10850764Smarkm et = et->next; 10950764Smarkm free(p); 11050764Smarkm } 11150764Smarkm} 112