#include "util.h"

#include <stdlib.h>
#include <string.h>

/* reimplementations of non-portable stdlib functions */

size_t EDL_internal_strnlen(const char* s, size_t maxlen) {
	size_t len;

	for (len = 0; len < maxlen; len++, s++) {
		if (!*s)
			break;
	}

	return len;
}

char* EDL_internal_strnchr(const char* haystack, char needle, size_t length) {
	for (; length && *haystack && *haystack != needle; haystack++, length--);

	return length ? haystack : NULL;
}

char* EDL_internal_strdup(const char* s) {
	const size_t len = strlen(s);

	char* d = malloc((len + 1) * sizeof(char));
	memcpy(d, s, len * sizeof(char));
	d[len] = '\0';

	return d;
}
