<commit_before>/* Copyright (C) 1996 <NAME> <<EMAIL>>
 * This file is part of the Linux-8086 C library and is distributed
 * under the GNU Library General Public License.
 */

/* This is an implementation of the C standard IO package.
 *
 * Updates:
 * 29-Sep-2000 <NAME>    1. fgetc copying beyond end of buffer
 *                              2. stdout needs flushed when input requested on
 *                                 stdin.
 *                              3. bufend was set incorrectly to 4 bytes beyond
 *                                 bufin (sizeof a pointer) instead of BUFSIZ.
 *                                 This resulted in 4 byte buffers for full
 *                                 buffered stdin and stdout and an 8 byte
 *                                 buffer for the unbuffered stderr!
 */


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <malloc.h>
#include <errno.h>
#include <string.h>

#undef STUB_FWRITE

extern FILE *__IO_list;			/* For fflush at exit */

#define FIXED_BUFFERS 2
struct fixed_buffer {
	unsigned char data[BUFSIZ];
	unsigned char used;
};

extern struct fixed_buffer _fixed_buffers[FIXED_BUFFERS];

extern unsigned char *_alloc_stdio_buffer(size_t size);
extern void _free_stdio_buffer(unsigned char *buf);

#ifdef L__alloc_stdio_buffer

unsigned char *_alloc_stdio_buffer(size_t size)
{
	if (size == BUFSIZ) {
		int i;

		for (i = 0; i < FIXED_BUFFERS; i++)
			if (!_fixed_buffers[i].used) {
				_fixed_buffers[i].used = 1;
				return _fixed_buffers[i].data;
			}
	}
	return malloc(size);
}
#endif

#ifdef L__free_stdio_buffer

void _free_stdio_buffer(unsigned char *buf)
{
	int i;

	for (i = 0; i < FIXED_BUFFERS; i++) {
		if (buf == _fixed_buffers[i].data) {
			_fixed_buffers[i].used = 0;
			return;
		}
	}
	free(buf);
}
#endif

#ifdef L__stdio_init

#if FIXED_BUFFERS < 2
#error FIXED_BUFFERS must be >= 2
#endif

#define bufin (_fixed_buffers[0].data)
#define bufout (_fixed_buffers[1].data)
#define buferr (_stdio_streams[3].unbuf)		/* Stderr is unbuffered */

struct fixed_buffer _fixed_buffers[FIXED_BUFFERS];
<commit_msg>Fixed stderr initialization bug (mine).<commit_after>/* Copyright (C) 1996 <NAME> <<EMAIL>>
 * This file is part of the Linux-8086 C library and is distributed
 * under the GNU Library General Public License.
 */

/* This is an implementation of the C standard IO package.
 *
 * Updates:
 * 29-Sep-2000 <NAME>    1. fgetc copying beyond end of buffer
 *                              2. stdout needs flushed when input requested on
 *                                 stdin.
 *                              3. bufend was set incorrectly to 4 bytes beyond
 *                                 bufin (sizeof a pointer) instead of BUFSIZ.
 *                                 This resulted in 4 byte buffers for full
 *                                 buffered stdin and stdout and an 8 byte
 *                                 buffer for the unbuffered stderr!
 */


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <malloc.h>
#include <errno.h>
#include <string.h>

#undef STUB_FWRITE

extern FILE *__IO_list;			/* For fflush at exit */

#define FIXED_BUFFERS 2
struct fixed_buffer {
	unsigned char data[BUFSIZ];
	unsigned char used;
};

extern struct fixed_buffer _fixed_buffers[FIXED_BUFFERS];

extern unsigned char *_alloc_stdio_buffer(size_t size);
extern void _free_stdio_buffer(unsigned char *buf);

#ifdef L__alloc_stdio_buffer

unsigned char *_alloc_stdio_buffer(size_t size)
{
	if (size == BUFSIZ) {
		int i;

		for (i = 0; i < FIXED_BUFFERS; i++)
			if (!_fixed_buffers[i].used) {
				_fixed_buffers[i].used = 1;
				return _fixed_buffers[i].data;
			}
	}
	return malloc(size);
}
#endif

#ifdef L__free_stdio_buffer

void _free_stdio_buffer(unsigned char *buf)
{
	int i;

	for (i = 0; i < FIXED_BUFFERS; i++) {
		if (buf == _fixed_buffers[i].data) {
			_fixed_buffers[i].used = 0;
			return;
		}
	}
	free(buf);
}
#endif

#ifdef L__stdio_init

#if FIXED_BUFFERS < 2
#error FIXED_BUFFERS must be >= 2
#endif

#define bufin (_fixed_buffers[0].data)
#define bufout (_fixed_buffers[1].data)
#define buferr (_stdio_streams[2].unbuf)		/* Stderr is unbuffered */

struct fixed_buffer _fixed_buffers[FIXED_BUFFERS];

{'fraction_non_alphanumeric': 0.10083449235048679, 'fraction_numerical': 0.013908205841446454, 'mean_word_length': 2.6629881154499153, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3664777', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1437, 'n_words': 434}