1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * com_right.c -- provide Heimdall / Kerberos4kth com_err interfaces
3*6a54128fSAndroid Build Coastguard Worker * for backwards compatibility
4*6a54128fSAndroid Build Coastguard Worker *
5*6a54128fSAndroid Build Coastguard Worker * Copyright (c) 2003 by Theodore Ts'o
6*6a54128fSAndroid Build Coastguard Worker *
7*6a54128fSAndroid Build Coastguard Worker * Taken from lib/com_err/error.c from Kerberos4kth distribution.
8*6a54128fSAndroid Build Coastguard Worker *
9*6a54128fSAndroid Build Coastguard Worker * Copyright (c) 1997, 1998, 2001 Kungliga Tekniska H�gskolan
10*6a54128fSAndroid Build Coastguard Worker * (Royal Institute of Technology, Stockholm, Sweden).
11*6a54128fSAndroid Build Coastguard Worker * All rights reserved.
12*6a54128fSAndroid Build Coastguard Worker *
13*6a54128fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
14*6a54128fSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions
15*6a54128fSAndroid Build Coastguard Worker * are met:
16*6a54128fSAndroid Build Coastguard Worker *
17*6a54128fSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright
18*6a54128fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
19*6a54128fSAndroid Build Coastguard Worker *
20*6a54128fSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright
21*6a54128fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the
22*6a54128fSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution.
23*6a54128fSAndroid Build Coastguard Worker *
24*6a54128fSAndroid Build Coastguard Worker * 3. Neither the name of the Institute nor the names of its contributors
25*6a54128fSAndroid Build Coastguard Worker * may be used to endorse or promote products derived from this software
26*6a54128fSAndroid Build Coastguard Worker * without specific prior written permission.
27*6a54128fSAndroid Build Coastguard Worker *
28*6a54128fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
29*6a54128fSAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30*6a54128fSAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31*6a54128fSAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
32*6a54128fSAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33*6a54128fSAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34*6a54128fSAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35*6a54128fSAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36*6a54128fSAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37*6a54128fSAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38*6a54128fSAndroid Build Coastguard Worker * SUCH DAMAGE.
39*6a54128fSAndroid Build Coastguard Worker */
40*6a54128fSAndroid Build Coastguard Worker
41*6a54128fSAndroid Build Coastguard Worker #include "config.h"
42*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
43*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
44*6a54128fSAndroid Build Coastguard Worker #include <string.h>
45*6a54128fSAndroid Build Coastguard Worker #include "com_err.h"
46*6a54128fSAndroid Build Coastguard Worker #include "error_table.h"
47*6a54128fSAndroid Build Coastguard Worker
48*6a54128fSAndroid Build Coastguard Worker const char *
com_right(struct et_list * list,long code)49*6a54128fSAndroid Build Coastguard Worker com_right(struct et_list *list, long code)
50*6a54128fSAndroid Build Coastguard Worker {
51*6a54128fSAndroid Build Coastguard Worker struct et_list *p;
52*6a54128fSAndroid Build Coastguard Worker for (p = list; p; p = p->next) {
53*6a54128fSAndroid Build Coastguard Worker if (code >= p->table->base && code < p->table->base + p->table->n_msgs)
54*6a54128fSAndroid Build Coastguard Worker return p->table->msgs[code - p->table->base];
55*6a54128fSAndroid Build Coastguard Worker }
56*6a54128fSAndroid Build Coastguard Worker return NULL;
57*6a54128fSAndroid Build Coastguard Worker }
58*6a54128fSAndroid Build Coastguard Worker
59*6a54128fSAndroid Build Coastguard Worker const char *
com_right_r(struct et_list * list,long code,char * str,size_t len)60*6a54128fSAndroid Build Coastguard Worker com_right_r(struct et_list *list, long code, char *str, size_t len)
61*6a54128fSAndroid Build Coastguard Worker {
62*6a54128fSAndroid Build Coastguard Worker struct et_list *p;
63*6a54128fSAndroid Build Coastguard Worker for (p = list; p; p = p->next) {
64*6a54128fSAndroid Build Coastguard Worker if ((code >= p->table->base) &&
65*6a54128fSAndroid Build Coastguard Worker (code < p->table->base + p->table->n_msgs)) {
66*6a54128fSAndroid Build Coastguard Worker strncpy(str, p->table->msgs[code - p->table->base], len);
67*6a54128fSAndroid Build Coastguard Worker str[len-1] = '\0';
68*6a54128fSAndroid Build Coastguard Worker return str;
69*6a54128fSAndroid Build Coastguard Worker }
70*6a54128fSAndroid Build Coastguard Worker }
71*6a54128fSAndroid Build Coastguard Worker return NULL;
72*6a54128fSAndroid Build Coastguard Worker }
73*6a54128fSAndroid Build Coastguard Worker
74*6a54128fSAndroid Build Coastguard Worker struct foobar {
75*6a54128fSAndroid Build Coastguard Worker struct et_list etl;
76*6a54128fSAndroid Build Coastguard Worker struct error_table tab;
77*6a54128fSAndroid Build Coastguard Worker };
78*6a54128fSAndroid Build Coastguard Worker
79*6a54128fSAndroid Build Coastguard Worker /*
80*6a54128fSAndroid Build Coastguard Worker * We provide this routine for compatibility with Heimdall generated
81*6a54128fSAndroid Build Coastguard Worker * foo_err.c files, but we don't use this ourselves for foo_err.c
82*6a54128fSAndroid Build Coastguard Worker * files generated by our compile_et. This is so our foo_err.c
83*6a54128fSAndroid Build Coastguard Worker * files can be used with older com_err libraries without running
84*6a54128fSAndroid Build Coastguard Worker * afoul of dependencies.
85*6a54128fSAndroid Build Coastguard Worker */
86*6a54128fSAndroid Build Coastguard Worker void
initialize_error_table_r(struct et_list ** list,const char ** messages,int num_errors,long base)87*6a54128fSAndroid Build Coastguard Worker initialize_error_table_r(struct et_list **list,
88*6a54128fSAndroid Build Coastguard Worker const char **messages,
89*6a54128fSAndroid Build Coastguard Worker int num_errors,
90*6a54128fSAndroid Build Coastguard Worker long base)
91*6a54128fSAndroid Build Coastguard Worker {
92*6a54128fSAndroid Build Coastguard Worker struct et_list *et, **end;
93*6a54128fSAndroid Build Coastguard Worker struct error_table *tab;
94*6a54128fSAndroid Build Coastguard Worker struct foobar *f;
95*6a54128fSAndroid Build Coastguard Worker
96*6a54128fSAndroid Build Coastguard Worker for (end = list, et = *list; et; end = &et->next, et = et->next)
97*6a54128fSAndroid Build Coastguard Worker if (et->table->msgs == messages)
98*6a54128fSAndroid Build Coastguard Worker return;
99*6a54128fSAndroid Build Coastguard Worker f = malloc(sizeof(*f));
100*6a54128fSAndroid Build Coastguard Worker if (f == NULL)
101*6a54128fSAndroid Build Coastguard Worker return;
102*6a54128fSAndroid Build Coastguard Worker et = &f->etl;
103*6a54128fSAndroid Build Coastguard Worker et->table = tab = &f->tab;
104*6a54128fSAndroid Build Coastguard Worker tab->msgs = messages;
105*6a54128fSAndroid Build Coastguard Worker tab->n_msgs = num_errors;
106*6a54128fSAndroid Build Coastguard Worker tab->base = base;
107*6a54128fSAndroid Build Coastguard Worker et->next = NULL;
108*6a54128fSAndroid Build Coastguard Worker *end = et;
109*6a54128fSAndroid Build Coastguard Worker }
110*6a54128fSAndroid Build Coastguard Worker
111*6a54128fSAndroid Build Coastguard Worker
112*6a54128fSAndroid Build Coastguard Worker void
free_error_table(struct et_list * et)113*6a54128fSAndroid Build Coastguard Worker free_error_table(struct et_list *et)
114*6a54128fSAndroid Build Coastguard Worker {
115*6a54128fSAndroid Build Coastguard Worker while(et){
116*6a54128fSAndroid Build Coastguard Worker struct et_list *p = et;
117*6a54128fSAndroid Build Coastguard Worker et = et->next;
118*6a54128fSAndroid Build Coastguard Worker free(p);
119*6a54128fSAndroid Build Coastguard Worker }
120*6a54128fSAndroid Build Coastguard Worker }
121