'\"macro stdmacro
.if n .pH ddi_dki.copymsg @(#)copymsg	40.6 of 10/10/89
.\" Copyright 1989 AT&T
.de IX
.ie '\\n(.z'' .tm .Index: \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9	\\n%
.el \\!.IX \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
..
.nr X
.if \nX=0 .ds x} copymsg D3DK "STREAMS" "DDI/DKI" "\&"
.if \nX=1 .ds x} copymsg D3DK "STREAMS" "DDI/DKI"
.if \nX=2 .ds x} copymsg D3DK "" "\&"
.if \nX=3 .ds x} copymsg "" "" "\&"
.TH \*(x}
.IX "\f4copymsg\fP(D3DK)"
.SH NAME 
\f4copymsg\f1 \- copy a message
.IX "STREAMS messages"
.SH "SYNOPSIS" 
.nf
.na
\f4#include <sys/stream.h>
.sp 0.5
mblk_t *copymsg(mblk_t \f2mp\f4);\f1
.ad
.fi
.SH "ARGUMENTS" 
.RS 0n 10
.IP "\f2mp\f1" 10n
Pointer to the message to be copied. \f4mblk_t\f1 is an instance of the
\f4msgb\f1(D4DK) structure.
.RE
.SH "DESCRIPTION" 
\f4copymsg\f1 forms a new message by allocating new message blocks, copies
the contents of the message referred to by
\f2mp\f1 (using the \f4copyb\f1(D3DK) function),
and returns a pointer to the new message.
.SH "RETURN VALUE" 
If the copy is successful, \f4copymsg\f1 returns a pointer to the new
message.  Otherwise, it returns a \f4NULL\f1 pointer.
.SH "LEVEL" 
Base or Interrupt
.SH "SEE ALSO" 
\f2BCI Driver Development Guide\f1, Chapter 7, ``STREAMS''
.P
.na
\f4allocb\f1(D3DK),
\f4copyb\f1(D3DK),
\f4msgb\f1(D4DK)
.ad
.SH "EXAMPLE" 
.IX "\f4copymsg\fP(D3DK), example"
.IX "\f4freemsg\fP(D3DK), example"
.P
The routine \f4lctouc\f1 converts all the lowercase
.SM ASCII
characters in the message to uppercase.
If the reference count is greater
than one (line 8), then the message is shared, and must be copied
before changing the contents of the data buffer.
If the call to the \f4copymsg\f1(D3DK) function fails (line 9),
return \f4NULL\fP (line 10), otherwise, free the original message (line 11).
If the reference count was equal to \f41\f1,
the message can be modified.
For each character (line 16) in each message block (line 15), if
it is a lowercase letter, convert it to an uppercase letter
line 18).
A pointer to the converted message is returned (line 21).
.ne 4
.P
.nf
.ft 4
.ps 7
 1  mblk_t *lctouc(mp)
 2	mblk_t *mp;
 3  {
 4	mblk_t *cmp;
 5	mblk_t *tmp;
 6	unsigned char *cp;
 7
 8	if (mp->b_datap->db_ref > 1) {
 9		if ((cmp = copymsg(mp)) == NULL)
10			return(NULL);
11		freemsg(mp);
12	} else {
13		cmp = mp;
14	}
15	for (tmp = cmp; tmp; tmp = tmp->b_next) {
16		for (cp = tmp->b_rptr; cp < tmp->b_wptr; cp++) {
17			if ((*cp <= 'z') && (*cp >= 'a'))
18				*cp -= 0x20;
19		}
20	}
21	return(cmp);
22  }
.ps
.ft 1
.fi
.P
.FG "copymsg \- copy a message"
