DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5 and SCO OpenServer 5

copymsg(D3str)


copymsg -- copy a message

Synopsis

   #include <sys/stream.h>
   #include <sys/ddi.h>
   

mblk_t *copymsg(mblk_t *mp);

Description

copymsg forms a new message by allocating new message blocks, copies the contents of the message referred to by mp (using the copyb(D3str) function), and returns a pointer to the new message.

Arguments


mp
Pointer to the message to be copied.

Return values

On success, copymsg returns a pointer to the new message. On failure, it returns a NULL pointer.

Usage

Warnings

Drivers should not assume that the memory allocated for the data buffer is usable for DMA operations, nor should drivers assume that the memory has any specific physical properties such as starting address alignment, physical address range, or physical contiguity. Beginning with DDI version 6, memory with specific physical properties can be obtained by using msgphysreq(D3str) after the copy or using allocb_physreq(D3str) and copy manually.

Context

Base or Interrupt.

Synchronization constraints

Does not block.

Driver-defined basic locks, read/write locks, and sleep locks may be held across calls to this function.

Examples

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)
    2	mblk_t *mp;
    3  {
    4	mblk_t *cmp;
    5	mblk_t *tmp;
    6	uchar_t *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  }

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp
oddi: 1, 2, 2mp, 3, 3mp, 4, 4mp, 5, 5mp, 6, 6mp

Differences between versions

In DDI versions 1, 2, 3, 4, 5, and 5mp, the memory for the data buffer(s) returned by copymsg will be DMA-able; that is, it will satisfy worst-case DMA-ability requirements on systems with restricted DMA and will be physically contiguous; see phys_dmasize of physreq(D4). For other versions, there are no guarantees on the memory properties.

References

allocb(D3str), allocb_physreq(D3str), copyb(D3str), msgphysreq(D3str), msgb(D4str)
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005