1copymsg(9F) Kernel Functions for Drivers copymsg(9F)
2
3
4
6 copymsg - copy a message
7
9 #include <sys/stream.h>
10
11
12
13 mblk_t *copymsg(mblk_t *mp);
14
15
17 Architecture independent level 1 (DDI/DKI).
18
20 mp Pointer to the message to be copied.
21
22
24 The copymsg() function forms a new message by allocating new message
25 blocks, and copying the contents of the message referred to by mp
26 (using the copyb(9F) function). It returns a pointer to the new mes‐
27 sage.
28
30 If the copy is successful, copymsg() returns a pointer to the new mes‐
31 sage. Otherwise, it returns a NULL pointer.
32
34 The copymsg() function can be called from user, interrupt, or kernel
35 context.
36
38 Example 1 : Using copymsg
39
40
41 The routine lctouc() converts all the lowercase ASCII characters in the
42 message to uppercase. If the reference count is greater than one (line
43 8), then the message is shared, and must be copied before changing the
44 contents of the data buffer. If the call to the copymsg() function
45 fails (line 9), return NULL (line 10), otherwise, free the original
46 message (line 11). If the reference count was equal to 1, the message
47 can be modified. For each character (line 16) in each message block
48 (line 15), if it is a lowercase letter, convert it to an uppercase let‐
49 ter (line 18). A pointer to the converted message is returned (line
50 21).
51
52
53
54 1 mblk_t *lctouc(mp)
55 2 mblk_t *mp;
56 3 {
57 4 mblk_t *cmp;
58 5 mblk_t *tmp;
59 6 unsigned char *cp;
60 7
61 8 if (mp->b_datap->db_ref > 1) {
62 9 if ((cmp = copymsg(mp)) == NULL)
63 10 return (NULL);
64 11 freemsg(mp);
65 12 } else {
66 13 cmp = mp;
67 14 }
68 15 for (tmp = cmp; tmp; tmp = tmp->b_cont) {
69 16 for (cp = tmp->b_rptr; cp < tmp->b_wptr; cp++) {
70 17 if ((*cp <= 'z') && (*cp >= 'a'))
71 18 *cp -= 0x20;
72 19 }
73 20 }
74 21 return(cmp);
75 22 }
76
77
79 allocb(9F), copyb(9F), msgb(9S)
80
81
82 Writing Device Drivers
83
84
85 STREAMS Programming Guide
86
87
88
89SunOS 5.11 16 Jan 2006 copymsg(9F)