view src/util.c @ 8:0c98b46eaf73 v2.0

*: update API to 2.0, big changes all APIs now use pointers to an EDL object. it is up to the user to make sure that the pointer is valid. additionally, many things have been separated into new files to make it easier to digest
author Paper <paper@paper.us.eu.org>
date Sun, 03 Mar 2024 17:56:58 -0500
parents
children d6f8f73a0c50
line wrap: on
line source

#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 != 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;
}