xref: /aosp_15_r20/external/e2fsprogs/lib/ss/request_tbl.c (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker  * Copyright 1987, 1988 by MIT Student Information Processing Board
3*6a54128fSAndroid Build Coastguard Worker  *
4*6a54128fSAndroid Build Coastguard Worker  * Permission to use, copy, modify, and distribute this software and
5*6a54128fSAndroid Build Coastguard Worker  * its documentation for any purpose is hereby granted, provided that
6*6a54128fSAndroid Build Coastguard Worker  * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7*6a54128fSAndroid Build Coastguard Worker  * advertising or publicity pertaining to distribution of the software
8*6a54128fSAndroid Build Coastguard Worker  * without specific, written prior permission.  M.I.T. and the
9*6a54128fSAndroid Build Coastguard Worker  * M.I.T. S.I.P.B. make no representations about the suitability of
10*6a54128fSAndroid Build Coastguard Worker  * this software for any purpose.  It is provided "as is" without
11*6a54128fSAndroid Build Coastguard Worker  * express or implied warranty.
12*6a54128fSAndroid Build Coastguard Worker  */
13*6a54128fSAndroid Build Coastguard Worker 
14*6a54128fSAndroid Build Coastguard Worker #include "config.h"
15*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_ERRNO_H
16*6a54128fSAndroid Build Coastguard Worker #include <errno.h>
17*6a54128fSAndroid Build Coastguard Worker #endif
18*6a54128fSAndroid Build Coastguard Worker 
19*6a54128fSAndroid Build Coastguard Worker #include "ss_internal.h"
20*6a54128fSAndroid Build Coastguard Worker 
21*6a54128fSAndroid Build Coastguard Worker #define ssrt ss_request_table	/* for some readable code... */
22*6a54128fSAndroid Build Coastguard Worker 
ss_add_request_table(int sci_idx,ssrt * rqtbl_ptr,int position,int * code_ptr)23*6a54128fSAndroid Build Coastguard Worker void ss_add_request_table(int sci_idx, ssrt *rqtbl_ptr, int position, int *code_ptr)
24*6a54128fSAndroid Build Coastguard Worker {
25*6a54128fSAndroid Build Coastguard Worker 	register ss_data *info;
26*6a54128fSAndroid Build Coastguard Worker 	register int i, size;
27*6a54128fSAndroid Build Coastguard Worker 	ssrt **t;
28*6a54128fSAndroid Build Coastguard Worker 
29*6a54128fSAndroid Build Coastguard Worker 	info = ss_info(sci_idx);
30*6a54128fSAndroid Build Coastguard Worker 	for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
31*6a54128fSAndroid Build Coastguard Worker 		;
32*6a54128fSAndroid Build Coastguard Worker 	/* size == C subscript of NULL == #elements */
33*6a54128fSAndroid Build Coastguard Worker 	size += 2;		/* new element, and NULL */
34*6a54128fSAndroid Build Coastguard Worker 	t = (ssrt **)realloc(info->rqt_tables, (unsigned)size*sizeof(ssrt *));
35*6a54128fSAndroid Build Coastguard Worker 	if (t == (ssrt **)NULL) {
36*6a54128fSAndroid Build Coastguard Worker 		*code_ptr = errno;
37*6a54128fSAndroid Build Coastguard Worker 		return;
38*6a54128fSAndroid Build Coastguard Worker 	}
39*6a54128fSAndroid Build Coastguard Worker 	info->rqt_tables = t;
40*6a54128fSAndroid Build Coastguard Worker 	if (position > size - 2)
41*6a54128fSAndroid Build Coastguard Worker 		position = size - 2;
42*6a54128fSAndroid Build Coastguard Worker 
43*6a54128fSAndroid Build Coastguard Worker 	if (size > 1)
44*6a54128fSAndroid Build Coastguard Worker 		for (i = size - 2; i >= position; i--)
45*6a54128fSAndroid Build Coastguard Worker 			info->rqt_tables[i+1] = info->rqt_tables[i];
46*6a54128fSAndroid Build Coastguard Worker 
47*6a54128fSAndroid Build Coastguard Worker 	info->rqt_tables[position] = rqtbl_ptr;
48*6a54128fSAndroid Build Coastguard Worker 	info->rqt_tables[size-1] = (ssrt *)NULL;
49*6a54128fSAndroid Build Coastguard Worker 	*code_ptr = 0;
50*6a54128fSAndroid Build Coastguard Worker }
51*6a54128fSAndroid Build Coastguard Worker 
ss_delete_request_table(int sci_idx,ssrt * rqtbl_ptr,int * code_ptr)52*6a54128fSAndroid Build Coastguard Worker void ss_delete_request_table(int sci_idx, ssrt *rqtbl_ptr, int *code_ptr)
53*6a54128fSAndroid Build Coastguard Worker {
54*6a54128fSAndroid Build Coastguard Worker      register ss_data *info;
55*6a54128fSAndroid Build Coastguard Worker      register ssrt **rt1, **rt2;
56*6a54128fSAndroid Build Coastguard Worker 
57*6a54128fSAndroid Build Coastguard Worker      *code_ptr = SS_ET_TABLE_NOT_FOUND;
58*6a54128fSAndroid Build Coastguard Worker      info = ss_info(sci_idx);
59*6a54128fSAndroid Build Coastguard Worker      rt1 = info->rqt_tables;
60*6a54128fSAndroid Build Coastguard Worker      for (rt2 = rt1; *rt1; rt1++) {
61*6a54128fSAndroid Build Coastguard Worker 	  if (*rt1 != rqtbl_ptr) {
62*6a54128fSAndroid Build Coastguard Worker 	       *rt2++ = *rt1;
63*6a54128fSAndroid Build Coastguard Worker 	       *code_ptr = 0;
64*6a54128fSAndroid Build Coastguard Worker 	  }
65*6a54128fSAndroid Build Coastguard Worker      }
66*6a54128fSAndroid Build Coastguard Worker      *rt2 = (ssrt *)NULL;
67*6a54128fSAndroid Build Coastguard Worker      return;
68*6a54128fSAndroid Build Coastguard Worker }
69