Commit 8fe9f929 8fe9f9292791c6f5ede4368553c728c4331718fb by Sam Roberts

message_create_copy(): creates a copy of a message, useful when you want

to operate on a temporary copy of a message.
1 parent 0e2610e1
......@@ -30,6 +30,8 @@ extern "C" {
extern int message_create __P ((message_t *, void *owner));
extern void message_destroy __P ((message_t *, void *owner));
extern int message_create_copy __P ((message_t *to, message_t from));
extern void * message_get_owner __P ((message_t));
extern int message_is_modified __P ((message_t));
extern int message_clear_modified __P ((message_t));
......
......@@ -162,6 +162,41 @@ message_destroy (message_t *pmsg, void *owner)
}
int
message_create_copy (message_t *to, message_t from)
{
int status = 0;
stream_t fromstr = NULL;
stream_t tostr = NULL;
off_t off = 0;
size_t n = 0;
char buf[512];
if(!to || !from)
return EINVAL;
if((status = message_create (to, NULL)))
return status;
message_get_stream (from, &fromstr);
message_get_stream (*to, &tostr);
while (
(status = stream_readline (fromstr, buf, sizeof(buf), off, &n)) == 0
&&
n > 0
)
{
stream_write (tostr, buf, n, off, NULL);
off += n;
}
if(status)
message_destroy(to, NULL);
return status;
}
int
message_ref (message_t msg)
{
if (msg)
......