]>
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.
9 #include "folder_realloc.h"
14 * Reallocate some of the space in the folder
15 * structure (currently just message status array).
17 * Return pointer to new folder structure.
18 * If error, return NULL.
22 folder_realloc (struct msgs
*mp
, int lo
, int hi
)
24 struct bvector
*tmpstats
, *t
;
30 die("BUG: called folder_realloc with lo (%d) < 1", lo
);
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)",
36 if (mp
->nummsg
> 0 && hi
< mp
->hghmsg
)
37 die("BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
40 /* Check if we really need to reallocate anything */
41 if (lo
== mp
->lowoff
&& hi
== mp
->hghoff
)
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
) {
51 /* then copy messages status array with shift */
53 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++)
54 bvector_copy (tmpstats
+ msgnum
- lo
, msgstat (mp
, msgnum
));
57 mp
->msgstats
= tmpstats
;