🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #689

Re: bash 1.04 doesn't compile on 4.3BSD

#689
From: Chet Ramey
Date: Fri, 10 Nov 1989 02:05
94 lines
2962 bytes
In article <8911080748.AA14217@skinfaxe.diku.dk> seindal@DIKU.DK (Rene' Seindal) writes:
>Bash 1.04 doesn't compile on 4.3BSD (and 4.2BSD), because these systems
>doesn't have setvbuf(3), but use setlinebuf(3) as a partial substitute.

On the other hand...

/*
 * An ANSI-compatible setvbuf() for those sites that need it (usually
 * 4.2BSD-derived systems, up to and including 4.3-tahoe).
 *
 * Bugs to chet@po.CWRU.Edu
 */

#ifndef _IOFBF
#define _IOFBF	0
#endif

int
setvbuf(iop, buf, type, size)
FILE 	*iop;
char	*buf;
int	type, size;
{
	/*
	 * Do a little sanity checking on type, and fail if an invalid
	 * type is given.
	 */

	if ((type != _IOFBF) && (type != _IOLBF) && (type != _IONBF))
		return EOF;

	/*
	 * If we already allocated something for this iop, clean up.
	 */

	if ((iop->_base != NULL) && (iop->_flag & _IOMYBUF))
		free(iop->_base);

	/*
	 * Clear out all previous settings before we start
	 */

	iop->_flag &= ~(_IOMYBUF | _IOFBF | _IONBF | _IOLBF);

	/*
	 * If we're specifying no buffering, all we need to do is set the
	 * appropriate flag and return, since buf and size are ignored.
	 */

	if (type == _IONBF) {
		iop->_flag |= _IONBF;
		iop->_ptr = iop->_base = (char *) NULL;
		iop->_bufsiz = iop->_cnt = 0;
		return 0;
	}

	/*
	 * If we specify full buffering or line buffering, but with a size of
	 * 0, then fail and return.
	 */

	if ((type == _IOFBF || type == _IOLBF) && (size == 0))
		return EOF;

	/*
	 * If we are not given a buffer, but we have a non-zero size, we must
	 * allocate one ourselves and set the corresponding flag.  Note that
	 * by the time we get here, we are assured that we have line or full
	 * buffering, so a buffer MUST be allocated if none is given.  If we
	 * can't allocate a buffer, fail and return.
	 */

	if (buf == NULL)
		if ((buf = (char *) malloc(size)) == NULL)
			return EOF;
		else
			iop->_flag |= _IOMYBUF;

	/*
	 * OK, we're almost home.  Set up the buffer and other stuff and
	 * return success.
	 */

	iop->_ptr = iop->_base = buf;
	iop->_cnt = 0;
	iop->_bufsiz = size;
	iop->_flag |= type;
	return 0;
}
-- 
Chet Ramey				"How terrible is wisdom when it 
Network Services Group			 brings no profit to the wise."
Case Western Reserve University			-- Mephistopheles 
chet@ins.CWRU.Edu			
Technical Details
Message-ID: <884@cwjcc.CWRU.Edu>
Path: arc1-ca.pugleaf.net!utzoo!yunexus!telly!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ukma!cwjcc!cwns1!chet
References: <8911080748.AA14217@skinfaxe.diku.dk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!yunexus!telly!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ukma!cwjcc!cwns1!chet
From: chet@cwns1.CWRU.EDU (Chet Ramey)
Newsgroups: gnu.bash.bug
Subject: Re: bash 1.04 doesn't compile on 4.3BSD
Summary: OK, here's a setvbuf()
Message-ID: <884@cwjcc.CWRU.Edu>
Date: 10 Nov 89 02:05:33 GMT
Article-I.D.: cwjcc.884
References: <8911080748.AA14217@skinfaxe.diku.dk>
Sender: news@cwjcc.CWRU.Edu
Reply-To: chet@po.CWRU.Edu (Chet Ramey)
Distribution: gnu
Organization: Case Western Reserve Univ. Cleveland, Ohio, (USA)
Lines: 94