copymsg(D3DK) —
.IX \f4copymsg\fP(D3DK)
NAME
copymsg − copy a message .IX STREAMS messages
SYNOPSIS
#include <sys/stream.h>
mblk_t ∗copymsg(mblk_t ∗mp);
ARGUMENTS
mpPointer to the message to be copied.
DESCRIPTION
copymsg forms a new message by allocating new message blocks, copies the contents of the message referred to by mp (using the copyb(D3DK) function), and returns a pointer to the new message.
RETURN VALUE
If successful, copymsg returns a pointer to the new message. Otherwise, it returns a NULL pointer.
LEVEL
Base or Interrupt.
NOTES
Does not sleep.
Driver-defined basic locks, read/write locks, and sleep locks may be held across calls to this function.
SEE ALSO
allocb(D3DK), copyb(D3DK), msgb(D4DK)
EXAMPLE
.IX \f4copymsg\fP(D3DK), example
.IX \f4freemsg\fP(D3DK), example
The routine lctouc converts all the lower case ASCII characters in the message to upper case. 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 copymsg fails (line 9), we return NULL (line 10). Otherwise, we free the original message (line 11). If the reference count was equal to one, the message can be modified. For each character (line 16) in each message block (line 15), if it is a lower case letter, we convert it to an upper case letter (line 18). When done, we return a pointer to the converted message (line 21).
1 mblk_t ∗lctouc(mp)
2mblk_t ∗mp;
3 {
4mblk_t ∗cmp;
5mblk_t ∗tmp;
6uchar_t ∗cp;
7
8if (mp->b_datap->db_ref > 1) {
9if ((cmp = copymsg(mp)) == NULL)
10return(NULL);
11freemsg(mp);
12} else {
13cmp = mp;
14}
15for (tmp = cmp; tmp; tmp = tmp->b_next) {
16for (cp = tmp->b_rptr; cp < tmp->b_wptr; cp++) {
17if ((∗cp <= ’z’) && (∗cp >= ’a’))
18∗cp -= 0x20;
19}
20}
21return(cmp);
22 }
DDI/DKI — STREAMS