Mercurial > libedl
view src/util.c @ 14:2d7c810a1ac2 default tip
*: misc. cleanup
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Fri, 03 May 2024 22:40:28 -0400 |
parents | d6f8f73a0c50 |
children |
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 && *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; }