<commit_before>#include <common/tty.h>
#include <string.h>

namespace libc{
	// cover in separate namespace to avoid name collision
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <fcntl.h>
	#include <unistd.h>
}


/* class definition */
/**
 * \brief	standard constructor
 */
tty::tty(){
	this->fd_in = 0;
	this->fd_out = 1;
}

/**
 * \brief	extended constructor
 *
 * \param	in_file		file to read from
 * \param	out_file	file to write to
 */
tty::tty(const char* in_file, const char* out_file){
	this->fd_in = libc::open(in_file, O_RDONLY);
	this->fd_out = libc::open(out_file, O_WRONLY);
}

/**
 * \brief	destructor
 */
tty::~tty(){
	if(this->fd_in > 1)
		libc::close(this->fd_in);

	if(this->fd_out > 1)
		libc::close(this->fd_out);
}

/**
 * \brief	read from fd_in
 *
 * \param	buf		target buffer
 * \param	nbytes	max bytes to read
 *
 * \return	number of read bytes on success
 * 			-1 on error
 */
int tty::read(void* buf, unsigned int nbytes){
	// TODO
	return libc::read(fd_in, buf, nbytes);
}

/**
 * \brief	write to fd_out
 *
 * \param	buf		source buffer
 * \param	nbytes	number of bytes to write
 *
 * \return	number of written bytes on success
 * 			-1 on error
 */
int tty::write(void* buf, unsigned int nbytes){
	// TODO
	return libc::write(fd_out, buf, nbytes);
}

int tty::write(char* s){
	return libc::write(fd_out, s, strlen(s));
}<commit_msg>[common: tty]<commit_after>#include <common/tty.h>
#include <string.h>

namespace libc{
	// cover in separate namespace to avoid name collision
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <fcntl.h>
	#include <unistd.h>
}


/* class definition */
/**
 * \brief	standard constructor
 */
tty::tty(){
	this->fd_in = 0;
	this->fd_out = 1;
}

/**
 * \brief	extended constructor
 *
 * \param	in_file		file to read from
 * \param	out_file	file to write to
 */
tty::tty(const char* in_file, const char* out_file){
	this->fd_in = libc::open(in_file, O_RDONLY);
	this->fd_out = libc::open(out_file, O_WRONLY);
}

/**
 * \brief	destructor
 */
tty::~tty(){
	if(this->fd_in > 1)
		libc::close(this->fd_in);

	if(this->fd_out > 1)
		libc::close(this->fd_out);
}

/**
 * \brief	read from fd_in
 *
 * \param	buf		target buffer
 * \param	nbytes	max bytes to read
 *
 * \return	number of read bytes on success
 * 			-1 on error
 */
int tty::read(void* buf, unsigned int nbytes){
	return libc::read(fd_in, buf, nbytes);
}

/**
 * \brief	write to fd_out
 *
 * \param	buf		source buffer
 * \param	nbytes	number of bytes to write
 *
 * \return	number of written bytes on success
 * 			-1 on error
 */
int tty::write(void* buf, unsigned int nbytes){
	return libc::write(fd_out, buf, nbytes);
}

int tty::write(char* s){
	return libc::write(fd_out, s, strlen(s));
}
{'fraction_non_alphanumeric': 0.16116005873715125, 'fraction_numerical': 0.004405286343612335, 'mean_word_length': 3.51158940397351, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, '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': '6108308', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1060, 'n_words': 291}