10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1846Scraigm * Common Development and Distribution License (the "License"). 6*1846Scraigm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1846Scraigm 220Sstevel@tonic-gate /* 23*1846Scraigm * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 30*1846Scraigm #pragma ident "%Z%%M% %I% %E% SMI" 31*1846Scraigm 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include "synonyms.h" 340Sstevel@tonic-gate #include "file64.h" 350Sstevel@tonic-gate #include "mtlib.h" 360Sstevel@tonic-gate #include <sys/types.h> 370Sstevel@tonic-gate #include <stdio.h> 380Sstevel@tonic-gate #include <stdlib.h> 390Sstevel@tonic-gate #include <thread.h> 400Sstevel@tonic-gate #include <synch.h> 410Sstevel@tonic-gate #include "stdiom.h" 420Sstevel@tonic-gate 430Sstevel@tonic-gate 440Sstevel@tonic-gate void 450Sstevel@tonic-gate setbuf(FILE *iop, char *abuf) 460Sstevel@tonic-gate { 470Sstevel@tonic-gate Uchar *buf = (Uchar *)abuf; 48*1846Scraigm int fno = GET_FD(iop); /* file number */ 490Sstevel@tonic-gate int size = BUFSIZ - _SMBFSZ; 500Sstevel@tonic-gate Uchar *temp; 510Sstevel@tonic-gate rmutex_t *lk; 520Sstevel@tonic-gate 530Sstevel@tonic-gate FLOCKFILE(lk, iop); 540Sstevel@tonic-gate if ((iop->_base != 0) && (iop->_flag & _IOMYBUF)) 550Sstevel@tonic-gate free((char *)iop->_base - PUSHBACK); 560Sstevel@tonic-gate iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); 570Sstevel@tonic-gate if (buf == 0) { 580Sstevel@tonic-gate iop->_flag |= _IONBF; 590Sstevel@tonic-gate #ifndef _STDIO_ALLOCATE 600Sstevel@tonic-gate if (fno < 2) { 610Sstevel@tonic-gate /* use special buffer for std{in,out} */ 620Sstevel@tonic-gate buf = (fno == 0) ? _sibuf : _sobuf; 630Sstevel@tonic-gate } else /* needed for ifndef */ 640Sstevel@tonic-gate #endif 650Sstevel@tonic-gate if (fno < _NFILE) { 660Sstevel@tonic-gate buf = _smbuf[fno]; 670Sstevel@tonic-gate size = _SMBFSZ - PUSHBACK; 680Sstevel@tonic-gate } else 690Sstevel@tonic-gate if ((buf = (Uchar *)malloc(_SMBFSZ * sizeof (Uchar))) != 0) { 700Sstevel@tonic-gate iop->_flag |= _IOMYBUF; 710Sstevel@tonic-gate size = _SMBFSZ - PUSHBACK; 720Sstevel@tonic-gate } 730Sstevel@tonic-gate } else { /* regular buffered I/O, standard buffer size */ 740Sstevel@tonic-gate if (isatty(fno)) 750Sstevel@tonic-gate iop->_flag |= _IOLBF; 760Sstevel@tonic-gate } 770Sstevel@tonic-gate if (buf == 0) { 780Sstevel@tonic-gate FUNLOCKFILE(lk); 790Sstevel@tonic-gate return; /* malloc() failed */ 800Sstevel@tonic-gate } 810Sstevel@tonic-gate temp = buf + PUSHBACK; 820Sstevel@tonic-gate iop->_base = temp; 830Sstevel@tonic-gate _setbufend(iop, temp + size); 840Sstevel@tonic-gate iop->_ptr = temp; 850Sstevel@tonic-gate iop->_cnt = 0; 860Sstevel@tonic-gate FUNLOCKFILE(lk); 870Sstevel@tonic-gate } 88