Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / ss / request_tbl.c
1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board
3  *
4  * For copyright information, see copyright.h.
5  */
6
7 #ifdef HAVE_ERRNO_H
8 #include <errno.h>
9 #endif
10
11 #include "copyright.h"
12 #include "ss_internal.h"
13
14 #define ssrt ss_request_table   /* for some readable code... */
15
16 void ss_add_request_table(sci_idx, rqtbl_ptr, position, code_ptr)
17         int sci_idx;
18         ssrt *rqtbl_ptr;
19         int position;           /* 1 -> becomes second... */
20         int *code_ptr;
21 {
22         register ss_data *info;
23         register int i, size;
24
25         info = ss_info(sci_idx);
26         for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
27                 ;
28         /* size == C subscript of NULL == #elements */
29         size += 2;              /* new element, and NULL */
30         info->rqt_tables = (ssrt **)realloc((char *)info->rqt_tables,
31                                             (unsigned)size*sizeof(ssrt));
32         if (info->rqt_tables == (ssrt **)NULL) {
33                 *code_ptr = errno;
34                 return;
35         }
36         if (position > size - 2)
37                 position = size - 2;
38
39         if (size > 1)
40                 for (i = size - 2; i >= position; i--)
41                         info->rqt_tables[i+1] = info->rqt_tables[i];
42
43         info->rqt_tables[position] = rqtbl_ptr;
44         info->rqt_tables[size-1] = (ssrt *)NULL;
45         *code_ptr = 0;
46 }
47
48 void ss_delete_request_table(sci_idx, rqtbl_ptr, code_ptr)
49      int sci_idx;
50      ssrt *rqtbl_ptr;
51      int *code_ptr;
52 {
53      register ss_data *info;
54      register ssrt **rt1, **rt2;
55
56      *code_ptr = SS_ET_TABLE_NOT_FOUND;
57      info = ss_info(sci_idx);
58      rt1 = info->rqt_tables;
59      for (rt2 = rt1; *rt1; rt1++) {
60           if (*rt1 != rqtbl_ptr) {
61                *rt2++ = *rt1;
62                *code_ptr = 0;
63           }
64      }
65      *rt2 = (ssrt *)NULL;
66      return;
67 }