4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.8 */
43 static int _mwrite ( MESG
* md
, char * msgbuf
, int );
48 * if it successfully writes all the queued message(s), or
49 * if some of them (errno is EAGAIN in this case).
50 * return -1 (with errno) when it failed.
59 if (md
== NULL
|| md
->mque
== NULL
) {
64 while ((p
= md
->mque
) != NULL
) {
65 if (_mwrite(md
, p
->dat
->buf
, p
->dat
->len
) != 0)
66 return (errno
== EAGAIN
? 0 : -1);
68 /* mwrite successful, get the next and free this entry */
81 * if it successfully writes the messages, or
82 * if it has been queued (errno is EAGAIN in this case)
83 * and md->mque is updated.
84 * return -1 (with errno) when it failed.
87 int mwrite ( MESG
* md
, char * msgbuf
)
107 if (LAST_MESSAGE
< stoh(msgbuf
+ MESG_TYPE
))
113 goto queue
; /* if there is a queue already, try to write all */
115 if (_mwrite(md
, msgbuf
, size
) == 0)
122 * fall through to queue the messages that cannot be sent now.
126 if ((p
= (MQUE
*)Malloc(sizeof(MQUE
))) == NULL
127 || (p
->dat
= (struct strbuf
*)Malloc(sizeof(struct strbuf
))) == NULL
128 || (p
->dat
->buf
= (char *)Malloc(size
)) == NULL
)
133 (void) memcpy(p
->dat
->buf
, msgbuf
, size
);
137 if ((q
= md
->mque
) != NULL
)
139 /* insert the new one to tail */
144 while ((p
= md
->mque
) != NULL
)
146 if (_mwrite(md
, p
->dat
->buf
, p
->dat
->len
) != 0) {
147 return (errno
== EAGAIN
? 0 : -1);
150 /* mwrite successful, get the next and free this entry */
163 int _mwrite ( MESG
* md
, char * msgbuf
, int size
)
174 if (size
<= 0 || size
> MSGMAX
)
181 ctl
.maxlen
= ctl
.len
= strlen(ctl
.buf
)+1;
183 dat
.maxlen
= dat
.len
= size
;
185 Lp_prio_msg
= 0; /* clean this up so there are no surprises */
187 if (Putmsg(md
, &ctl
, &dat
, flag
) == 0)
193 switch (write3_2(md
, msgbuf
, size
))