]>
diplodocus.org Git - nmh/blob - sbr/folder_realloc.c
3 * folder_realloc.c -- realloc a folder/msgs structure
11 * Reallocate some of the space in the folder
12 * structure (currently just message status array).
14 * Return pointer to new folder structure.
15 * If error, return NULL.
19 folder_realloc (struct msgs
*mp
, int lo
, int hi
)
25 adios (NULL
, "BUG: called folder_realloc with lo (%d) < 1", lo
);
27 adios (NULL
, "BUG: called folder_realloc with hi (%d) < 1", hi
);
28 if (mp
->nummsg
> 0 && lo
> mp
->lowmsg
)
29 adios (NULL
, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
31 if (mp
->nummsg
> 0 && hi
< mp
->hghmsg
)
32 adios (NULL
, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
35 /* Check if we really need to reallocate anything */
36 if (lo
== mp
->lowoff
&& hi
== mp
->hghoff
)
39 if (lo
== mp
->lowoff
) {
41 * We are just extending (or shrinking) the end of message
42 * status array. So we don't have to move anything and can
43 * just realloc the message status array.
45 if (!(mp
->msgstats
= realloc (mp
->msgstats
, MSGSTATSIZE(mp
, lo
, hi
)))) {
46 advise (NULL
, "unable to reallocate message storage");
51 * We are changing the offset of the message status
52 * array. So we will need to shift everything.
56 /* first allocate the new message status space */
57 if (!(tmpstats
= malloc (MSGSTATSIZE(mp
, lo
, hi
)))) {
58 advise (NULL
, "unable to reallocate message storage");
62 /* then copy messages status array with shift */
64 for (msgnum
= mp
->lowmsg
; msgnum
<= mp
->hghmsg
; msgnum
++)
65 tmpstats
[msgnum
- lo
] = mp
->msgstats
[msgnum
- mp
->lowoff
];
68 mp
->msgstats
= tmpstats
;
75 * Clear all the flags for entries outside
76 * the current message range for this folder.
79 for (msgnum
= mp
->lowoff
; msgnum
< mp
->lowmsg
; msgnum
++)
80 clear_msg_flags (mp
, msgnum
);
81 for (msgnum
= mp
->hghmsg
+ 1; msgnum
<= mp
->hghoff
; msgnum
++)
82 clear_msg_flags (mp
, msgnum
);
84 /* no messages, so clear entire range */
85 for (msgnum
= mp
->lowoff
; msgnum
<= mp
->hghoff
; msgnum
++)
86 clear_msg_flags (mp
, msgnum
);