blob: 16cb4213e91eecf8f7c46827f24480f33c7a0558 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * Copyright 1987, 1988 by MIT Student Information Processing Board
3 *
Theodore Ts'o06cefee1999-10-23 01:16:22 +00004 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose is hereby granted, provided that
6 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7 * advertising or publicity pertaining to distribution of the software
8 * without specific, written prior permission. M.I.T. and the
9 * M.I.T. S.I.P.B. make no representations about the suitability of
10 * this software for any purpose. It is provided "as is" without
11 * express or implied warranty.
Theodore Ts'o3839e651997-04-26 13:21:57 +000012 */
13
Theodore Ts'o50e1e101997-04-26 13:58:21 +000014#ifdef HAVE_ERRNO_H
15#include <errno.h>
16#endif
17
Theodore Ts'o3839e651997-04-26 13:21:57 +000018#include "ss_internal.h"
19
20#define ssrt ss_request_table /* for some readable code... */
21
JP Abgralle0ed7402014-03-19 19:08:39 -070022void ss_add_request_table(int sci_idx, ssrt *rqtbl_ptr, int position, int *code_ptr)
Theodore Ts'o3839e651997-04-26 13:21:57 +000023{
24 register ss_data *info;
25 register int i, size;
Jim Meyering671326f2009-02-23 18:26:05 +010026 ssrt **t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000027
28 info = ss_info(sci_idx);
29 for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
30 ;
31 /* size == C subscript of NULL == #elements */
32 size += 2; /* new element, and NULL */
JP Abgralle0ed7402014-03-19 19:08:39 -070033 t = (ssrt **)realloc(info->rqt_tables, (unsigned)size*sizeof(ssrt *));
Jim Meyering671326f2009-02-23 18:26:05 +010034 if (t == (ssrt **)NULL) {
Theodore Ts'o3839e651997-04-26 13:21:57 +000035 *code_ptr = errno;
36 return;
37 }
Jim Meyering671326f2009-02-23 18:26:05 +010038 info->rqt_tables = t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000039 if (position > size - 2)
40 position = size - 2;
41
42 if (size > 1)
43 for (i = size - 2; i >= position; i--)
44 info->rqt_tables[i+1] = info->rqt_tables[i];
45
46 info->rqt_tables[position] = rqtbl_ptr;
47 info->rqt_tables[size-1] = (ssrt *)NULL;
48 *code_ptr = 0;
49}
50
JP Abgralle0ed7402014-03-19 19:08:39 -070051void ss_delete_request_table(int sci_idx, ssrt *rqtbl_ptr, int *code_ptr)
Theodore Ts'o3839e651997-04-26 13:21:57 +000052{
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}