<commit_before>/*
 * setbuf.c - control buffering of a stream
 */
/* $Id$ */

#include	<stdio.h>
#include	<stdlib.h>
#include	"loc_incl.h"

extern void (*_clean)(void);

int
setvbuf(register FILE *stream, char *buf, int mode, size_t size)
{
	int retval = 0;

	_clean = __cleanup;
	if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
		return EOF;

	if (stream->_buf && io_testflag(stream,_IOMYBUF) )
		free((void *)stream->_buf);

	stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);

	if (!buf && (mode != _IONBF)) {
		if ((buf = (char *) malloc(size)) == NULL) {
			retval = EOF;
		} else {
			stream->_flags |= _IOMYBUF;
		}
	}

	if (io_testflag(stream, _IOREADING) || io_testflag(stream, _IOWRITING))
		retval = EOF;<commit_msg>Fixed obscure bug in setvbuf<commit_after>/*
 * setbuf.c - control buffering of a stream
 */
/* $Id$ */

#include	<stdio.h>
#include	<stdlib.h>
#include	"loc_incl.h"

extern void (*_clean)(void);

int
setvbuf(register FILE *stream, char *buf, int mode, size_t size)
{
	int retval = 0;

	_clean = __cleanup;
	if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
		return EOF;

	if (stream->_buf && io_testflag(stream,_IOMYBUF) )
		free((void *)stream->_buf);

	stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);

	if (buf && size <= 0) retval = EOF;
	if (!buf && (mode != _IONBF)) {
		if (size <= 0 || (buf = (char *) malloc(size)) == NULL) {
			retval = EOF;
		} else {
			stream->_flags |= _IOMYBUF;
		}
	}

	if (io_testflag(stream, _IOREADING) || io_testflag(stream, _IOWRITING))
		retval = EOF;
{'fraction_non_alphanumeric': 0.18027433050293926, 'fraction_numerical': 0.002612671456564337, 'mean_word_length': 3.7430340557275543, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2958796', 'n_tokens_mistral': 656, 'n_tokens_neox': 620, 'n_words': 153}