<commit_before>#include "string.h"
#include "limits.h"
#include "stdlib.h" // MIN

static const char *_errs[] = {
#include "string_strerrs.h"
};


size_t strlen(const char *s)
{
	int i = 0;
	while(*s++)
		i++;
	return i;
}

const char *strerror(int eno)
{
	// TODO: bounds check + snprintf
	return _errs[eno - 1];
}

int strncmp(const char *a, const char *b, size_t n)
{
	while(n > 0){
		int diff;
		char ac, bc;

		ac = *a;
		bc = *b;

		if(ac + bc == 0) /* both '\0' */
			return 0;
		else if(!ac)
			return -1;
		else if(!bc)
			return 1;

		diff = ac - bc;
		if(diff)
			return diff;

		n--;
		a++;
		b++;
	}
	return 0;
}

int strcmp(const char *a, const char *b)
{
	return strncmp(a, b, UINT_MAX);
}

char *strchr(const char *s, char c)
{
	while(*s)
		if(*s == c)
			return s;
		else
			s++;
	return NULL;
}

void *memset(void *p, unsigned char c, size_t len)
{
	void *const start = p;
	// TODO: asm / duff's device
	while(len > 0)
		*(char *)p++ = c;
	return start;
}

void *memcpy(char *to, const char *from, size_t count)
{
	/* TODO: repnz movsb */
	/* thank you duff */
	char *const ret = to;<commit_msg>Fixed memset() lib bug<commit_after>#include "string.h"
#include "limits.h"
#include "stdlib.h" // MIN

static const char *_errs[] = {
#include "string_strerrs.h"
};


size_t strlen(const char *s)
{
	int i = 0;
	while(*s++)
		i++;
	return i;
}

const char *strerror(int eno)
{
	// TODO: bounds check + snprintf
	return _errs[eno - 1];
}

int strncmp(const char *a, const char *b, size_t n)
{
	while(n > 0){
		int diff;
		char ac, bc;

		ac = *a;
		bc = *b;

		if(ac + bc == 0) /* both '\0' */
			return 0;
		else if(!ac)
			return -1;
		else if(!bc)
			return 1;

		diff = ac - bc;
		if(diff)
			return diff;

		n--;
		a++;
		b++;
	}
	return 0;
}

int strcmp(const char *a, const char *b)
{
	return strncmp(a, b, UINT_MAX);
}

char *strchr(const char *s, char c)
{
	while(*s)
		if(*s == c)
			return s;
		else
			s++;
	return NULL;
}

void *memset(void *p, unsigned char c, size_t len)
{
	void *const start = p;
	// TODO: asm / duff's device
	while(len-- > 0)
		*(char *)p++ = c;
	return start;
}

void *memcpy(char *to, const char *from, size_t count)
{
	/* TODO: repnz movsb */
	/* thank you duff */
	char *const ret = to;
{'fraction_non_alphanumeric': 0.1779168529280286, 'fraction_numerical': 0.008940545373267769, 'mean_word_length': 2.7804054054054053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4766906', 'n_tokens_mistral': 1055, 'n_tokens_neox': 965, 'n_words': 298}