2 ** folder_realloc.c -- realloc a folder/msgs structure
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
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)
28 adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with lo (%d) < 1", lo);
30 adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with hi (%d) < 1", hi);
31 if (mp->nummsg > 0 && lo > mp->lowmsg)
32 adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
34 if (mp->nummsg > 0 && hi < mp->hghmsg)
35 adios(EX_SOFTWARE, 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 if (lo == mp->lowoff) {
44 ** We are just extending (or shrinking) the end of message
45 ** status array. So we don't have to move anything and can
46 ** just realloc the message status array.
48 mp->msgstats = mh_xrealloc(mp->msgstats, MSGSTATSIZE(mp, lo, hi));
50 ** Clear the newly allocated msg flag space. The lowoff and
51 ** hghoff are the old messagenumber range. So the calculation
52 ** of the first new element has to subtract lowoff.
54 memset(mp->msgstats + mp->hghoff - lo + 1, 0, hi - mp->hghoff);
57 ** We are changing the offset of the message status
58 ** array. So we will need to shift everything.
62 /* first allocate the new message status space */
63 tmpstats = mh_xcalloc(MSGSTATSIZE(mp, lo, hi), 1);
65 /* then copy messages status array with shift */
67 for (msgnum=mp->lowmsg; msgnum<=mp->hghmsg; msgnum++) {
68 tmpstats[msgnum - lo] = mp->msgstats[msgnum - mp->lowoff];
71 mh_free0(&(mp->msgstats));
72 mp->msgstats = tmpstats;