xref: /titanic_51/usr/src/man/man9f/copymsg.9f (revision deef35fd18fdfb1c42002a4793ebb2c181b08680)
te
Copyright 1989 AT&T
Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
COPYMSG 9F "Jan 16, 2006"
NAME
copymsg - copy a message
SYNOPSIS

#include <sys/stream.h>



mblk_t *copymsg(mblk_t *mp);
INTERFACE LEVEL

Architecture independent level 1 (DDI/DKI).

PARAMETERS
mp

Pointer to the message to be copied.

DESCRIPTION

The copymsg() function forms a new message by allocating new message blocks, and copying the contents of the message referred to by mp (using the copyb(9F) function). It returns a pointer to the new message.

RETURN VALUES

If the copy is successful, copymsg() returns a pointer to the new message. Otherwise, it returns a NULL pointer.

CONTEXT

The copymsg() function can be called from user, interrupt, or kernel context.

EXAMPLES

Example 1 : Using copymsg

The routine lctouc() converts all the lowercase 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 copymsg() function fails (line 9), return NULL (line 10), otherwise, free the original message (line 11). If the reference count was equal to 1, 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).


 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_cont) {
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 }
SEE ALSO

allocb(9F), copyb(9F), msgb(9S)

Writing Device Drivers

STREAMS Programming Guide