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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.10 */
37 ** Choose at least one byte that won't appear in the body or header
40 unsigned char Resync
[HEAD_RESYNC_LEN
] = { 0x01, 0xFE };
41 unsigned char Endsync
[HEAD_RESYNC_LEN
] = { 0x02, 0xFD };
45 ** write_fifo() - WRITE A BUFFER WITH HEADER AND CHECKSUM
49 int write_fifo ( int fifo
, char * buf
, unsigned int size
)
51 int write_fifo (fifo
, buf
, size
)
57 unsigned short chksum
= 0;
60 (void)memcpy (buf
+ HEAD_RESYNC
, Resync
, HEAD_RESYNC_LEN
);
61 (void)memcpy (buf
+ TAIL_ENDSYNC(size
), Endsync
, TAIL_ENDSYNC_LEN
);
63 CALC_CHKSUM (buf
, size
, chksum
);
64 (void)htos (buf
+ TAIL_CHKSUM(size
), chksum
);
68 ** A message must be written in one call, to avoid interleaving
69 ** messages from several processes.
71 ** The caller is responsible for trapping SIGPIPE, so
72 ** we just return what the "write()" system call does.
74 ** Well, almost. If the pipe was almost full, we may have
75 ** written a partial message. If this is the case, we lie
76 ** and say the pipe was full, so the caller can try again.
78 ** read_fifo can deal with a truncated message, so we let it
79 ** do the grunt work associated with partial messages.
81 ** NOTE: Writing the remainder of the message is not feasible
82 ** as someone else may have written something to the fifo
83 ** while we were setting up to retry.
86 if ((wbytes
= write(fifo
, buf
, size
)) > 0)