]> diplodocus.org Git - nmh/blob - sbr/folder_realloc.c
sendsbr.c: Move interface to own file.
[nmh] / sbr / folder_realloc.c
1 /* folder_realloc.c -- realloc a folder/msgs structure
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include "h/mh.h"
9 #include "folder_realloc.h"
10 #include "error.h"
11 #include "h/utils.h"
12
13 /*
14 * Reallocate some of the space in the folder
15 * structure (currently just message status array).
16 *
17 * Return pointer to new folder structure.
18 * If error, return NULL.
19 */
20
21 struct msgs *
22 folder_realloc (struct msgs *mp, int lo, int hi)
23 {
24 struct bvector *tmpstats, *t;
25 size_t i;
26 int msgnum;
27
28 /* sanity checks */
29 if (lo < 1)
30 die("BUG: called folder_realloc with lo (%d) < 1", lo);
31 if (hi < 1)
32 die("BUG: called folder_realloc with hi (%d) < 1", hi);
33 if (mp->nummsg > 0 && lo > mp->lowmsg)
34 die("BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
35 lo, mp->lowmsg);
36 if (mp->nummsg > 0 && hi < mp->hghmsg)
37 die("BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
38 hi, mp->hghmsg);
39
40 /* Check if we really need to reallocate anything */
41 if (lo == mp->lowoff && hi == mp->hghoff)
42 return mp;
43
44 /* first allocate the new message status space */
45 mp->num_msgstats = MSGSTATNUM (lo, hi);
46 tmpstats = mh_xmalloc (MSGSTATSIZE(mp));
47 for (i = 0, t = tmpstats; i < mp->num_msgstats; ++i, ++t) {
48 bvector_init(t);
49 }
50
51 /* then copy messages status array with shift */
52 if (mp->nummsg > 0) {
53 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
54 bvector_copy (tmpstats + msgnum - lo, msgstat (mp, msgnum));
55 }
56 free(mp->msgstats);
57 mp->msgstats = tmpstats;
58 mp->lowoff = lo;
59 mp->hghoff = hi;
60
61 return mp;
62 }