xref: /onnv-gate/usr/src/lib/krb5/ss/request_tbl.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 2000 by Sun Microsystems, Inc.
3*0Sstevel@tonic-gate  * All rights reserved.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate /*
9*0Sstevel@tonic-gate  * Copyright 1987, 1988 by MIT Student Information Processing Board
10*0Sstevel@tonic-gate  *
11*0Sstevel@tonic-gate  * For copyright information, see copyright.h.
12*0Sstevel@tonic-gate  */
13*0Sstevel@tonic-gate 
14*0Sstevel@tonic-gate #include "copyright.h"
15*0Sstevel@tonic-gate #include "ss_internal.h"
16*0Sstevel@tonic-gate 
17*0Sstevel@tonic-gate #define ssrt ss_request_table	/* for some readable code... */
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate void
20*0Sstevel@tonic-gate ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
21*0Sstevel@tonic-gate 	int sci_idx;
22*0Sstevel@tonic-gate 	ssrt *rqtbl_ptr;
23*0Sstevel@tonic-gate 	int position;		/* 1 -> becomes second... */
24*0Sstevel@tonic-gate 	int *code_ptr;
25*0Sstevel@tonic-gate {
26*0Sstevel@tonic-gate 	register ss_data *info;
27*0Sstevel@tonic-gate 	register int i, size;
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate 	info = ss_info(sci_idx);
30*0Sstevel@tonic-gate 	for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
31*0Sstevel@tonic-gate 		;
32*0Sstevel@tonic-gate 	/* size == C subscript of NULL == #elements */
33*0Sstevel@tonic-gate 	size += 2;		/* new element, and NULL */
34*0Sstevel@tonic-gate 	info->rqt_tables = (ssrt **)realloc((char *)info->rqt_tables,
35*0Sstevel@tonic-gate 					    (unsigned)size*sizeof(ssrt));
36*0Sstevel@tonic-gate 	if (info->rqt_tables == (ssrt **)NULL) {
37*0Sstevel@tonic-gate 		*code_ptr = errno;
38*0Sstevel@tonic-gate 		return;
39*0Sstevel@tonic-gate 	}
40*0Sstevel@tonic-gate 	if (position > size - 2)
41*0Sstevel@tonic-gate 		position = size - 2;
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate 	if (size > 1)
44*0Sstevel@tonic-gate 		for (i = size - 2; i >= position; i--)
45*0Sstevel@tonic-gate 			info->rqt_tables[i+1] = info->rqt_tables[i];
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate 	info->rqt_tables[position] = rqtbl_ptr;
48*0Sstevel@tonic-gate 	info->rqt_tables[size-1] = (ssrt *)NULL;
49*0Sstevel@tonic-gate 	*code_ptr = 0;
50*0Sstevel@tonic-gate }
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate void
53*0Sstevel@tonic-gate ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
54*0Sstevel@tonic-gate      int sci_idx;
55*0Sstevel@tonic-gate      ssrt *rqtbl_ptr;
56*0Sstevel@tonic-gate      int *code_ptr;
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate      register ss_data *info;
59*0Sstevel@tonic-gate      register ssrt **rt1, **rt2;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate      *code_ptr = SS_ET_TABLE_NOT_FOUND;
62*0Sstevel@tonic-gate      info = ss_info(sci_idx);
63*0Sstevel@tonic-gate      rt1 = info->rqt_tables;
64*0Sstevel@tonic-gate      for (rt2 = rt1; *rt1; rt1++) {
65*0Sstevel@tonic-gate 	  if (*rt1 != rqtbl_ptr) {
66*0Sstevel@tonic-gate 	       *rt2++ = *rt1;
67*0Sstevel@tonic-gate 	       *code_ptr = 0;
68*0Sstevel@tonic-gate 	  }
69*0Sstevel@tonic-gate      }
70*0Sstevel@tonic-gate      *rt2 = (ssrt *)NULL;
71*0Sstevel@tonic-gate      return;
72*0Sstevel@tonic-gate }
73