tasign-kernel-shim 0.1.0

Kernel-side C shims for tasign/mbedTLS (strstr, snprintf).
Documentation
/* SPDX-License-Identifier: MIT
 * strstr + libc snprintf symbol for bare-metal link (mbedTLS PEM / X509).
 * snprintf delegates to mpaland printf (see c/mpaland/). */

#include <stdarg.h>
#include <stddef.h>

int vsnprintf_(char *buffer, size_t count, const char *format, va_list va);

static char *strstr_impl(const char *haystack, const char *needle)
{
	if (!haystack || !needle || !needle[0]) {
		return (char *)haystack;
	}
	for (; *haystack; haystack++) {
		const char *h = haystack;
		const char *n = needle;
		while (*h && *n && (unsigned char)*h == (unsigned char)*n) {
			h++;
			n++;
		}
		if (!*n) {
			return (char *)haystack;
		}
	}
	return 0;
}

char *strstr(const char *haystack, const char *needle)
{
	return strstr_impl(haystack, needle);
}

int snprintf(char *buf, size_t n, const char *fmt, ...)
{
	va_list ap;
	int r;

	va_start(ap, fmt);
	r = vsnprintf_(buf, n, fmt, ap);
	va_end(ap);
	return r;
}