4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
34 * Ptr args aren't checked for NULL because the program would be a
35 * catastrophic mess anyway. Better to abort than just to return NULL.
44 #include <sys/types.h>
51 fputs(const char *ptr
, FILE *iop
)
53 ssize_t ndone
= 0L, n
;
54 unsigned char *cptr
, *bufend
;
62 _SET_ORIENTATION_BYTE(iop
);
68 bufend
= _bufend(iop
);
71 if ((iop
->_flag
& _IONBF
) == 0) {
72 for (; ; ptr
+= len
, ptrlen
-= len
) {
73 while ((n
= bufend
- (cptr
= iop
->_ptr
)) <= 0) {
75 if (_xflsbuf(iop
) == EOF
) {
81 * n: number of available bytes in the buffer of 'iop'
82 * ptrlen: number of remaining bytes in 'ptr' string
84 * If all remaining bytes in 'ptr' can be copied into
85 * the buffer of 'iop' (ptrlen <= n), 'len' is set to
86 * 'ptrlen'. Otherwise, 'len' is set to 'n'.
87 * Then, copies 'len' bytes from 'ptr' to the buffer
90 len
= (c
= (ptrlen
<= n
)) ? ptrlen
: n
;
91 (void) memcpy(cptr
, ptr
, len
);
94 if (_needsync(iop
, bufend
))
95 _bufsync(iop
, bufend
);
99 * All bytes in 'ptr' have been copied into
100 * the buffer of 'iop'.
101 * Flush buffer if line-buffered
103 if (iop
->_flag
& _IOLBF
)
104 if (_xflsbuf(iop
) == EOF
) {
109 if (ndone
<= INT_MAX
)
118 /* write out to an unbuffered file */
120 ssize_t count
= (ssize_t
)ptrlen
;
121 int fd
= GET_FD(iop
);
123 while ((num_wrote
= write(fd
, ptr
, (size_t)count
)) != count
) {
124 if (num_wrote
<= 0) {
125 if (!cancel_active())
126 iop
->_flag
|= _IOERR
;
134 if (ptrlen
<= INT_MAX
)
135 return ((int)ptrlen
);