15e9cd1aeSAssar Westerlund /* 2*ae771770SStanislav Sedov * Copyright (c) 1997, 1998, 2001 Kungliga Tekniska Högskolan 35e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden). 45e9cd1aeSAssar Westerlund * All rights reserved. 55e9cd1aeSAssar Westerlund * 65e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without 75e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions 85e9cd1aeSAssar Westerlund * are met: 95e9cd1aeSAssar Westerlund * 105e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright 115e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer. 125e9cd1aeSAssar Westerlund * 135e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright 145e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the 155e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution. 165e9cd1aeSAssar Westerlund * 175e9cd1aeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors 185e9cd1aeSAssar Westerlund * may be used to endorse or promote products derived from this software 195e9cd1aeSAssar Westerlund * without specific prior written permission. 205e9cd1aeSAssar Westerlund * 215e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 225e9cd1aeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 235e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 245e9cd1aeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 255e9cd1aeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 265e9cd1aeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 275e9cd1aeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 285e9cd1aeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 295e9cd1aeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 305e9cd1aeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 315e9cd1aeSAssar Westerlund * SUCH DAMAGE. 325e9cd1aeSAssar Westerlund */ 335e9cd1aeSAssar Westerlund 34*ae771770SStanislav Sedov 355e9cd1aeSAssar Westerlund #include <config.h> 36*ae771770SStanislav Sedov 375e9cd1aeSAssar Westerlund #include <stdio.h> 385e9cd1aeSAssar Westerlund #include <stdlib.h> 395e9cd1aeSAssar Westerlund #include <string.h> 405e9cd1aeSAssar Westerlund #include <com_right.h> 41*ae771770SStanislav Sedov #include <roken.h> 425e9cd1aeSAssar Westerlund 43*ae771770SStanislav Sedov #ifdef LIBINTL 44*ae771770SStanislav Sedov #include <libintl.h> 45*ae771770SStanislav Sedov #else 46*ae771770SStanislav Sedov #define dgettext(d,s) (s) 47*ae771770SStanislav Sedov #endif 48*ae771770SStanislav Sedov 49*ae771770SStanislav Sedov KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL 505e9cd1aeSAssar Westerlund com_right(struct et_list *list, long code) 515e9cd1aeSAssar Westerlund { 525e9cd1aeSAssar Westerlund struct et_list *p; 53*ae771770SStanislav Sedov for (p = list; p; p = p->next) 545e9cd1aeSAssar Westerlund if (code >= p->table->base && code < p->table->base + p->table->n_msgs) 555e9cd1aeSAssar Westerlund return p->table->msgs[code - p->table->base]; 56*ae771770SStanislav Sedov return NULL; 57*ae771770SStanislav Sedov } 58*ae771770SStanislav Sedov 59*ae771770SStanislav Sedov KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL 60*ae771770SStanislav Sedov com_right_r(struct et_list *list, long code, char *str, size_t len) 61*ae771770SStanislav Sedov { 62*ae771770SStanislav Sedov struct et_list *p; 63*ae771770SStanislav Sedov for (p = list; p; p = p->next) { 64*ae771770SStanislav Sedov if (code >= p->table->base && code < p->table->base + p->table->n_msgs) { 65*ae771770SStanislav Sedov const char *msg = p->table->msgs[code - p->table->base]; 66*ae771770SStanislav Sedov #ifdef LIBINTL 67*ae771770SStanislav Sedov char domain[12 + 20]; 68*ae771770SStanislav Sedov snprintf(domain, sizeof(domain), "heim_com_err%d", p->table->base); 69*ae771770SStanislav Sedov #endif 70*ae771770SStanislav Sedov strlcpy(str, dgettext(domain, msg), len); 71*ae771770SStanislav Sedov return str; 72*ae771770SStanislav Sedov } 735e9cd1aeSAssar Westerlund } 745e9cd1aeSAssar Westerlund return NULL; 755e9cd1aeSAssar Westerlund } 765e9cd1aeSAssar Westerlund 775e9cd1aeSAssar Westerlund struct foobar { 785e9cd1aeSAssar Westerlund struct et_list etl; 795e9cd1aeSAssar Westerlund struct error_table et; 805e9cd1aeSAssar Westerlund }; 815e9cd1aeSAssar Westerlund 82*ae771770SStanislav Sedov KRB5_LIB_FUNCTION void KRB5_LIB_CALL 835e9cd1aeSAssar Westerlund initialize_error_table_r(struct et_list **list, 845e9cd1aeSAssar Westerlund const char **messages, 855e9cd1aeSAssar Westerlund int num_errors, 865e9cd1aeSAssar Westerlund long base) 875e9cd1aeSAssar Westerlund { 88adb0ddaeSAssar Westerlund struct et_list *et, **end; 895e9cd1aeSAssar Westerlund struct foobar *f; 90adb0ddaeSAssar Westerlund for (end = list, et = *list; et; end = &et->next, et = et->next) 915e9cd1aeSAssar Westerlund if (et->table->msgs == messages) 925e9cd1aeSAssar Westerlund return; 935e9cd1aeSAssar Westerlund f = malloc(sizeof(*f)); 945e9cd1aeSAssar Westerlund if (f == NULL) 955e9cd1aeSAssar Westerlund return; 965e9cd1aeSAssar Westerlund et = &f->etl; 975e9cd1aeSAssar Westerlund et->table = &f->et; 985e9cd1aeSAssar Westerlund et->table->msgs = messages; 995e9cd1aeSAssar Westerlund et->table->n_msgs = num_errors; 1005e9cd1aeSAssar Westerlund et->table->base = base; 101adb0ddaeSAssar Westerlund et->next = NULL; 102adb0ddaeSAssar Westerlund *end = et; 1035e9cd1aeSAssar Westerlund } 1045e9cd1aeSAssar Westerlund 1055e9cd1aeSAssar Westerlund 106*ae771770SStanislav Sedov KRB5_LIB_FUNCTION void KRB5_LIB_CALL 1075e9cd1aeSAssar Westerlund free_error_table(struct et_list *et) 1085e9cd1aeSAssar Westerlund { 1095e9cd1aeSAssar Westerlund while(et){ 1105e9cd1aeSAssar Westerlund struct et_list *p = et; 1115e9cd1aeSAssar Westerlund et = et->next; 1125e9cd1aeSAssar Westerlund free(p); 1135e9cd1aeSAssar Westerlund } 1145e9cd1aeSAssar Westerlund } 115