]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - lib/ss/request_tbl.c
Clean up sparse warnings
[thirdparty/e2fsprogs.git] / lib / ss / request_tbl.c
CommitLineData
3839e657
TT
1/*
2 * Copyright 1987, 1988 by MIT Student Information Processing Board
3 *
06cefee5
TT
4 * 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.
3839e657
TT
12 */
13
d1154eb4 14#include "config.h"
50e1e10f
TT
15#ifdef HAVE_ERRNO_H
16#include <errno.h>
17#endif
18
3839e657
TT
19#include "ss_internal.h"
20
21#define ssrt ss_request_table /* for some readable code... */
22
f404167d 23void ss_add_request_table(int sci_idx, ssrt *rqtbl_ptr, int position, int *code_ptr)
3839e657
TT
24{
25 register ss_data *info;
26 register int i, size;
671326f6 27 ssrt **t;
3839e657
TT
28
29 info = ss_info(sci_idx);
30 for (size=0; info->rqt_tables[size] != (ssrt *)NULL; size++)
31 ;
32 /* size == C subscript of NULL == #elements */
33 size += 2; /* new element, and NULL */
e46c187a 34 t = (ssrt **)realloc(info->rqt_tables, (unsigned)size*sizeof(ssrt *));
671326f6 35 if (t == (ssrt **)NULL) {
3839e657
TT
36 *code_ptr = errno;
37 return;
38 }
671326f6 39 info->rqt_tables = t;
3839e657
TT
40 if (position > size - 2)
41 position = size - 2;
42
43 if (size > 1)
44 for (i = size - 2; i >= position; i--)
45 info->rqt_tables[i+1] = info->rqt_tables[i];
46
47 info->rqt_tables[position] = rqtbl_ptr;
48 info->rqt_tables[size-1] = (ssrt *)NULL;
49 *code_ptr = 0;
50}
51
f404167d 52void ss_delete_request_table(int sci_idx, ssrt *rqtbl_ptr, int *code_ptr)
3839e657
TT
53{
54 register ss_data *info;
55 register ssrt **rt1, **rt2;
56
57 *code_ptr = SS_ET_TABLE_NOT_FOUND;
58 info = ss_info(sci_idx);
59 rt1 = info->rqt_tables;
60 for (rt2 = rt1; *rt1; rt1++) {
61 if (*rt1 != rqtbl_ptr) {
62 *rt2++ = *rt1;
63 *code_ptr = 0;
64 }
65 }
66 *rt2 = (ssrt *)NULL;
67 return;
68}