]>
diplodocus.org Git - nmh/blob - sbr/folder_realloc.c
1 /* folder_realloc.c -- realloc a folder/msgs structure
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.
12 * Reallocate some of the space in the folder
13 * structure (currently just message status array).
15 * Return pointer to new folder structure.
16 * If error, return NULL.
20 folder_realloc (struct msgs
*mp
, int lo
, int hi
)
22 struct bvector
*tmpstats
, *t
;
28 adios (NULL
, "BUG: called folder_realloc with lo (%d) < 1", lo
);
30 adios (NULL
, "BUG: called folder_realloc with hi (%d) < 1", hi
);
31 if (mp
->nummsg
> 0 && lo
> mp
->lowmsg
)
32 adios (NULL
, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
34 if (mp
->nummsg
> 0 && hi
< mp
->hghmsg
)
35 adios (NULL
, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
38 /* Check if we really need to reallocate anything */
39 if (lo
== mp
->lowoff
&& hi
== mp
->hghoff
)
42 /* first allocate the new message status space */
43 mp
->num_msgstats
= MSGSTATNUM (lo
, hi
);
44 tmpstats
= mh_xmalloc (MSGSTATSIZE(mp
));
45 for (i
= 0, t
= tmpstats
; i
< mp
->num_msgstats
; ++i
, ++t
) {
49 /* then copy messages status array with shift */
51 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++)
52 bvector_copy (tmpstats
+ msgnum
- lo
, msgstat (mp
, msgnum
));
55 mp
->msgstats
= tmpstats
;